---
title: "Why am I not able to append an image only if certain classes exist?"  
description: "Why am I not able to append an image only if certain classes exist?"  
author: "Jayden Bell"  
published: 2013-04-09  
updated: 2013-04-09  
canonical: https://www.mindstick.com/forum/739/why-am-i-not-able-to-append-an-image-only-if-certain-classes-exist  
category: "jquery"  
tags: ["jquery"]  
reading_time: 1 minute  

---

# Why am I not able to append an image only if certain classes exist?

Hi Everyone!\
I [am trying](https://answers.mindstick.com/qa/36834/which-two-programming-languages-should-i-master-in-if-i-am-trying-to-get-into-google-or-facebook) to use jQuery to append an [image tag](https://www.mindstick.com/forum/431/problem-with-image-tag) to a div only if one of three classes [exists](https://www.mindstick.com/forum/158947/how-do-you-use-the-exists-operator-to-check-for-the-existence-of-records-in-a-subquery), but it doesn't seem to be working. It either appends to all \
of the [elements](https://www.mindstick.com/forum/1440/wpf-button-with-multiple-text-elements) or none at all.\
Here is the HTML code:\
<[figure](https://yourviews.mindstick.com/view/87536/what-are-ghosts-jobs-and-how-to-figure-out-them) [class](https://www.mindstick.com/blog/165/generic-class-in-c-sharp)="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](https://www.mindstick.com/interview/1067/what-is-the-php-predefined-variable-that-tells-the-what-type-of-images-that-php-support)/schoolProfile/donut-plus-minus.png" />'); }\
Thanks in [advance](https://www.mindstick.com/blog/33258/jee-mains-and-jee-advance-exams)

## Replies

### Reply by AVADHESH PATEL

Hi Jayden!\
you can try this way\
$("figure.donut") .filter(".plus, .minus, .plus-minus") .find(".figure-value") .append('<img src="../images/schoolProfile/donut-plus-minus.png" />');\
This will find all of the figures with a class of donut and plus, minus or plus-minus and then find the element with a class of figure-value inside them and append the [image](https://www.mindstick.com/articles/23551/an-investigate-distinctive-seafood-restaurant-for-your-image-stamp-character).\
In answer to the comment below, change the append to create a jQuery object and apply the css to that:\
.append($('<img src="../images/schoolProfile/donut-plus-minus.png" />') .css({"top": -100+"px", "left": 0+"px"}));\
I hope it solve your problem\


---

Original Source: https://www.mindstick.com/forum/739/why-am-i-not-able-to-append-an-image-only-if-certain-classes-exist

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
