简体   繁体   中英

Remove <br /> after image using jquery or javascript

I have...

<td align="right" vAlign="top">
<img src="test/test.gif" width="1" height="4" border="0"><br />
Number<font color="#CC0000">*</font>:
</td><td></td><td>

How do I ditch that hanging <br /> with jquery? I've tried a ton of examples here ,but nothing works. Any ideas?

你试过这个吗?

$("img").next("br").remove();

Assuming you want to remove all <br> that follow an <img> you can use this:

$('img + br').remove()

If you prefer it to apply only to those inside a <td> :

$('td > img + br').remove()

I'd suggest:

$('img + br').remove();

This seems to be, in Chromium 22/Ubuntu 12.10, just under twice as fast as the approach using next() : JS Perf comparison .

References:

really no reason to use JavaScript here, because it can be easily done with CSS:

img + br {display:none;}

;-)

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