开发者

remove <br> with jquery

开发者 https://www.devze.com 2023-01-11 03:30 出处:网络
I have the following markup which is just a small portion of the total markup. <div align=\"center\">

I have the following markup which is just a small portion of the total markup.

<div align="center">
  <img src开发者_如何学Go="v/vspfiles/templates/100/images/headings/heading_shoppingcart.gif">
</div>
<br><br>

I would like to remove the two <br> tags.

Note: there are other <br> tags on the page both before this and after this that I do not want to removed.

I thought of using a selector to target the div by the src which contains heading_shoppingcart.gif and something like .after and then .remove the <br>.

Unsure of the correct syntax or if there is a better/easier way to do it.


This will safely retain any subsequent <br> elements since you seemed to allude to the idea that there may be more that should be preserved.

$('img[src$=heading_shoppingcart.gif]').parent().nextUntil(':not(br)').remove();


How about:

$("img[src$='heading_shoppingcart.gif']").parent().nextAll('br').remove()
  • The [$=] is the 'attribute ends with' selector.
  • .parent() moves up to the containing element
  • .nextAll() gets all following siblings


$('[src~=images/headings/heading_shoppingcart.gif]').parent().nextAll('br').remove();


I think the following would work:

var br1 = $("img[src='v/vspfiles/templates/100/images/headings/heading_shoppingcart.gif']").parent("div").next("br");

br1.add(br1.next("br")).remove();
0

精彩评论

暂无评论...
验证码 换一张
取 消