9

i want to delete a particular class from my object as my requirement is to delete that dom data before displaying content. I have written a sample code but not able to get why that is not working. I jquery's remove is also not working. Please help me to get it solve. Thanks in advance

<html>
<head>
<title>test</title>
<script type="text/javascript" src="jquery-1.5.min.js"></script>
<script type="text/javascript">
  $(document).ready(function() {

    // complete html
    var test;
    test = $('#issue_detail_first_row').html();

    var x = $(test).find('#issue_detail_nav').not('.p1');

    $('#sett').html(x);
 });

</script>
 </head>
 <body>
 <div id="issueDetailContainer">
        <div  id="issue_detail_first_row">
            <div>
                <div id="issue_detail_nav">
                    <div>test</div>
                    <div id="gett">
                        <div class="p1">
                            this content need to be deleted 1
                        </div>
                    </div>

                    <div class="p1">
                        this content need to be deleted 2
                    </div>

                </div>
            </div>                
        </div>
        <br/><br/><br/><br/>
<div id="sett">
</div>

1
  • 2
    How are you using $.remove()? Commented Jul 14, 2011 at 15:18

3 Answers 3

15

You need to remove the content from the DOM directly.

$("#issue_detail_first_row .p1").remove();

That will select the .p1 elements and remove them from the DOM

Sign up to request clarification or add additional context in comments.

Comments

9

you can use remove function on javascript object.

If you want to preprocess it before displaying.

example

var a =$("#issue_detail_first_row").html();
var jhtml =$(a)[0];   
$(jhtml).find('.p1').remove();
alert($(jhtml).html());

now use jhtml . demo

http://jsfiddle.net/WXPab/14/

Comments

7

It seems that you're trying to duplicate a section, but without the .p1 elements.

You could use the clone()[docs] method to clone the section, the remove()[docs] method to remove what you don't want, and then insert its HTML.

$(document).ready(function() {

    var test = $('#issue_detail_first_row').clone();  // clone it

    test.find('.p1').remove();  // find and remove the class p1 elements

    $('#sett').html( test.html() );  // insert the new content
});

Working example: http://jsfiddle.net/YDZ9U/1/

Only thing is that you'll need to go through and update the IDs in the clone, so that they're not duplicated on the page.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.