简体   繁体   中英

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

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.

It is the next sibling of the element with class one_third

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

Demo: Fiddle

您可以在jQuery中使用next()remove()方法

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

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();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM