Click here to Skip to main content
15,911,711 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
hello all ,

i want to remove all div tag of first jcrop-holder class except image tag
HTML
<p>
<div class="jcrop-holder">
<div></div>
<div></div>
<img src="img.png" />
</div>

<div class="jcrop-holder">
<div></div>
<div></div>
</div>
</p>


expected output
===============
HTML
<p>
<div class="jcrop-holder">
<img src="img.png" />
</div>
 
<div class="jcrop-holder">
<div></div>
<div></div>
</div>
</p>


i used this one but i cant get result -->>

$(".jcrop-holder:first").not("img").remove();

thanks in advance
Posted
Updated 10-May-13 2:37am
v7

Try below code

JavaScript
$('div.jcrop-holder:first').find('div').remove();
 
Share this answer
 
Try this ..
XML
<!DOCTYPE html>
<html>
<head>
  <script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js">
  </script>
  <script>
    $(document).ready(function () {
      $("#btn").click(function () {

        var allListElements = $(".jcrop-holder").find('*');
        debugger
        for (var i = 0; i < allListElements.length; i++) {
          if (allListElements[i] != 'img')
            $(allListElements[i]).remove();
        }

      });
    });
  </script>
</head>
<body>
  <button type="button" id="btn">Click Me!</button>
  <p>
    <div class="jcrop-holder">
      <div>1</div>
      <div>2</div>
      <div class="img">img</div>
      <img class="img" />
    </div>

    <div class="jcrop-holder">
      <div>3</div>
      <div>4</div>
    </div>
  </p>
</body>
</html>
 
Share this answer
 
Try this ..

simple one ..
$(".jcrop-holder div:not('.img')").remove();

OR
$(".jcrop-holder div:not('img')").remove();
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900