CSS Selector
Use the selector notation for finding a node by it's attribute
[title="element title attribute value"]
Using JavaScript
Same selector as in CSS, but you can get the Node using document.querySelector
, or if expecting multiple Nodes, a NodeList via document.querySelectorAll
var node = document.querySelector('[title="element title attribute value"]');
When you do .innerHTML
, you are causing a re-parse of all HTML in the node you've called it on and this can literally destroy sections of web pages. You should use DOM methods for creating nodes, instead. e.g.
var style = document.createElement('style');
style.appendChild(document.createTextNode('div {border: 1px solid red}'));
document.body.appendChild(style);
Converting JavaScript into a bookmarklet is as simple as
bookmarklet = 'javascript:'
+ encodeURIComponent('(function () {' + code + '}())')
+ ';';
Here is a fiddle where you can just paste in code
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…