admin管理员组文章数量:1220092
I want to be able to remove only spans which has an id that stars with the key word "junk_"
for example if I have
<span id="junk_8345">A</span>
<span id="valid_2972">B</span>
<span id="junk_9249">C</span>
The output should look like
<span id="valid_2972">B</span>
I've tried to use
$("span:has(junk)").remove();
but it does not seem to work. I'm open to use regex expression with the replace function if I can accomplish the same goal. Any help would be greatly appreciated!
I want to be able to remove only spans which has an id that stars with the key word "junk_"
for example if I have
<span id="junk_8345">A</span>
<span id="valid_2972">B</span>
<span id="junk_9249">C</span>
The output should look like
<span id="valid_2972">B</span>
I've tried to use
$("span:has(junk)").remove();
but it does not seem to work. I'm open to use regex expression with the replace function if I can accomplish the same goal. Any help would be greatly appreciated!
Share Improve this question asked Nov 14, 2011 at 21:20 Eyad FallatahEyad Fallatah 1,9484 gold badges24 silver badges36 bronze badges2 Answers
Reset to default 15use the startswith
selector.
$('span[id^="junk"]').remove();
Based on what the API page give about "selectors" ( http://api.jquery.com/category/selectors/ ), I suggest you trying to use the start with ^=.
http://api.jquery.com/attribute-starts-with-selector/
$('span[id^="junk"]').remove();
本文标签: javascriptjQuery Remove specific span based on idStack Overflow
版权声明:本文标题:javascript - jQuery Remove specific span based on id - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1739334064a2158619.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论