Vignesh Pichamani
Vignesh Pichamani

Reputation: 8070

Remove <br> tag using jquery?

Good Day.

Actually it is the wordpress site but i need the general solution using jquery(if feasible) I trying to remove the
tag next to end of the div.

See I am using the div as like here

    <div class="one_third">
<p>This is for testing</p>
    </div>
    <br> <!--This one -->
    <div class="one_third">
    </div>
    <br><!--This one -->
    <div class="one_third">
    </div>
    <br><!--This one -->

In the above example i am using the class of one_third in a div inside this div i am using br tag too. But all i am want to remove the br tag which is in outside the div i mean in the end of the div in jquery.

</div>
<br>

I am not sure how to do this in jquery (Actually i try with wordpress disable wpautop is removing the br tag which is inside the div too (I don't want to remove the br tag inside the div only outside the div i mean end of the div )).

Any suggestion would be great :)

Thanks, vicky

Upvotes: 0

Views: 2231

Answers (4)

Pranav C Balan
Pranav C Balan

Reputation: 115242

You can use next() and remove() methods in jQuery for that

$(".one_third").next('br').remove();

Upvotes: 3

epascarello
epascarello

Reputation: 207527

A non JavaScript solution would be a simple CSS sibling selector

.one_third + br { 
    display : none; 
}

If you really want to use jQuery, you can use the same selector and use remove()

$(".one_third + br").remove();

Upvotes: 3

adeneo
adeneo

Reputation: 318302

You should just place the HTML on one line.
wpautop inserts <br> on newlines, so placing the HTML code on one line avoids the entire issue.

<div class="one_third"><p>This is for testing</p></div><div class="one_third"></div><div class="one_third"></div>

The way you structure the markup is everything when wpautop is enabled.

Upvotes: 7

Arun P Johny
Arun P Johny

Reputation: 388416

It is the next sibling of the element with class one_third

$('.one_third').next('br').remove()

Demo: Fiddle

Upvotes: 6

Related Questions