How to remove <br> tag from two <br> tags using jQuery
Published by Aslam
Here is a nice solution for those who want to remove one tag from where two tags comes together.
<p>A paragraph</p> <br> <br> <p>Another Paragraph</p> <br> <br> <p>Another Paragraph</p>
So, if you have used blogger to post something, you may have noticed that when we click enter, it automatically interpreted as a tag.
:I have felt this problem in my blog too:
So the basic selector syntax using jQuery is
jQuery('document').ready(function() { $( ' br + br').remove(); }
If you want ot remove one tag only within <pre> tags, then it comes like this
jQuery('document').ready(function() { $( 'pre br + br').remove(); }
After loading the page, above example will converted to
<p>A paragraph</p> <br> <p>Another Paragraph</p> <br> <p>Another Paragraph</p>
Here is the final solution for those who want to remove All doubled tags.
jQuery('document').ready(function() {
$( 'br + br').remove();
}
And here is the solution for those who want to remove All doubled tags only within <pre> tags.
jQuery('document').ready(function() {
$( 'br + br').remove();
}
Below is other ways with jQuery. These will work. but above solution is recommended!
$('br').next('br').remove();
$('br').prev('br').remove();
Comments
Post a Comment