forum

Home / DeveloperSection / Forums / Why am I not able to append an image only if certain classes exist?

Why am I not able to append an image only if certain classes exist?

Jayden Bell201209-Apr-2013
Hi Everyone!

I am trying to use jQuery to append an image tag to a div only if one of three classes exists, but it doesn't seem to be working. It either appends to all 

of the elements or none at all.

Here is the HTML code:

<figure class="donut minus">
    <div class="figure-value"></div>
</figure>
Here is the jQuery:

if ($("figure.donut").hasClass("minus") || $("figure.donut").hasClass("plus") || $("figure.donut").hasClass("plus-minus")) {
        $(".figure-value").append('<img src="../images/schoolProfile/donut-plus-minus.png" />');
    }

Thanks in advance

Updated on 09-Apr-2013

Can you answer this question?


Answer

1 Answers

Liked By