admin管理员组文章数量:1266931
I want to pleately wipe the title attribute from all elements inside a html doc. From table, p, img, div etc..
Currently I do this:
$(document).ready(function(){
$("a").removeAttr("title");
$("img").removeAttr("title");
$("div").removeAttr("title");
// and so on
// and so on
// and so on
});
Is there a more elegant way to do this? Without selecting individual elements?
I want to pleately wipe the title attribute from all elements inside a html doc. From table, p, img, div etc..
Currently I do this:
$(document).ready(function(){
$("a").removeAttr("title");
$("img").removeAttr("title");
$("div").removeAttr("title");
// and so on
// and so on
// and so on
});
Is there a more elegant way to do this? Without selecting individual elements?
Share Improve this question asked Aug 22, 2016 at 14:01 MalasorteMalasorte 1,1737 gold badges23 silver badges47 bronze badges 3- 1 But why would you? – Rudie Visser Commented Aug 22, 2016 at 14:03
- When HTML is loaded on a touch screen device I just want the title to go away. – Malasorte Commented Aug 22, 2016 at 14:04
- $('[title]').removeAttr('title'); You could use the attribute selector so that it just loads elements with the attribute of title instead of every element on your page. api.jquery./has-attribute-selector – Sean Wessell Commented Aug 22, 2016 at 14:11
4 Answers
Reset to default 5Use the attribute selector and select just the elements with the title attribute and not all elements.
$("[title]").removeAttr("title");
The all selector, *
, selector should do the trick
$('*').removeAttr('title');
You can simply do this using All Selector (“*”)
:
$("*").removeAttr("title");
Without jQuery this would be:
Array.from(document.getElementsByTagName('*')).forEach(elem => elem.removeAttribute('title'));
or e.g. to remove the attribute only from specific tags, e.g. img
:
Array.from(document.getElementsByTagName('img')).forEach(elem => elem.removeAttribute('title'));
本文标签: javascriptRemove attribute title from all HTML elementsStack Overflow
版权声明:本文标题:javascript - Remove attribute title from all HTML elements - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741077042a2335487.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论