admin管理员组文章数量:1297057
if the h2 has the word ply i want to add a break.
the titles are dynamically called, the site is html so i can't use php on anything.
heres the h2
11/400-5 4 PLY EXPERIMENTAL TIRE AIRCRAFT TIRE
want it to look like this
11/400-5 4 PLY
EXPERIMENTAL TIRE AIRCRAFT TIRE
so any title that has the word PLY in it will add a break right after the word.
probably pretty easy for all yous out there =)
if the h2 has the word ply i want to add a break.
the titles are dynamically called, the site is html so i can't use php on anything.
heres the h2
11/400-5 4 PLY EXPERIMENTAL TIRE AIRCRAFT TIRE
want it to look like this
11/400-5 4 PLY
EXPERIMENTAL TIRE AIRCRAFT TIRE
so any title that has the word PLY in it will add a break right after the word.
probably pretty easy for all yous out there =)
Share Improve this question asked Oct 26, 2010 at 22:34 AlexAlex 6332 gold badges8 silver badges13 bronze badges3 Answers
Reset to default 8Example: http://jsfiddle/DbJ2V/
$('h2:contains(" PLY ")').html( function(i,htm) {
return htm.replace(" PLY ", " PLY<br/>");
});
Let's try answer instead of menting:
$("h2:contains('PLY')").each(function() {
$(this).html($(this).html().replace(/(\WPLY\W)/g, "$1<br />"));
});
First we look for any h2 with the text 'PLY
', then replace it, if it is indeed not part of a word (for example, -PLY
would match, _PLY
wouldn't, blame regexes for what is part of a word and what is not), with the same content plus a <br />
.
Try:
$(document).ready(function() {
$("#content h2:contains(' PLY ')").each(function(k,v) {
t = $(v).text();
$(v).html(t.replace(" PLY ", " PLY<br/>"));
});
});
本文标签: javascriptjquery add ltbrgt to h2 if h2 contains this wordStack Overflow
版权声明:本文标题:javascript - jquery add <br> to h2 if h2 contains this word - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741640701a2389899.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论