简体   繁体   中英

how to remove a div on the basis of a class using jQuery

I'm using this to remove the div whenever I call my showresult(); function. I am dynamically creating this div <div class="sampageswrapper"> , so this needs to be removed when ever showresult() is called.

function showresult(data) {
  jQuery('.sampageswrapper div').remove();
  // rest of my code.
}

But unfortunately this div is not removing.

<div class="sampageswrapper">
  <div id="image_div" class="img_class" name="image_div">
    ..........
  </div>
</div>

you can use the .samepageswrapper selector only

jQuery('.sampageswrapper').remove();

it should target that specific div.

when you use .sampageswrapper div as your selector, this targets all the div's inside the div element with sampageswrapper class

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM