jquery - Why am I not able to append an image only if certain classes exist? -
i trying use jquery append image tag div if 1 of 3 classes exists, doesn't seem working. either appends of elements or none @ all.
here html code:
<figure class="donut minus"> <div class="figure-value"></div> </figure>
here 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" />'); }
instead of if try using filter:
$("figure.donut") .filter(".plus, .minus, .plus-minus") .find(".figure-value") .append('<img src="../images/schoolprofile/donut-plus-minus.png" />');
this find of figures class of donut , plus, minus or plus-minus , find element class of figure-value inside them , append image.
jsfiddle example - http://jsfiddle.net/7fuam/
in answer comment below, change append create jquery object , apply css that:
.append($('<img src="../images/schoolprofile/donut-plus-minus.png" />') .css({"top": -100+"px", "left": 0+"px"}));
update example - http://jsfiddle.net/infernalbadger/7fuam/1/
Comments
Post a Comment