0

I have the following code in a php page

<div class="vmenu">

  <div class="first_li"><span >Add Shift</span></div>
 <div class="first_li"><span>Add Comment</span></div>

 </div>

Now I want to remove the div contains text "Add Shift" on document ready

2
  • Do you want to remove it with PHP from a string or you want to remove it with JS from DOM? Mar 28, 2012 at 6:35
  • you need to accept answers at least for your previous questions! Mar 28, 2012 at 6:49

3 Answers 3

1
$(function(){

    $('.first_li span:contains('Add Shift')').remove();
});
2
  • $('.first_li span:contains('Add Shift')').remove(); is working fine but how to add again it. Actually I am doing this on condition basis. so I want to add it again in else condition Mar 28, 2012 at 6:39
  • like this: $('div.vmenu div:first-child').hide(); Mar 28, 2012 at 6:43
1

Use jQuery .remove() and :contains(). Note that it's case sensitive

$('div:contains("Add Shift")').remove();
0
$('div.vmenu div:first-child').remove();

check it out on jsfiddle: http://jsfiddle.net/7CFAq/

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.