Stop when we hit an ID for shorter selectors path
This commit is contained in:
Родитель
a0bb23a752
Коммит
71e04757a2
4
index.js
4
index.js
|
@ -175,8 +175,10 @@
|
|||
|
||||
var parents = []
|
||||
while (element) {
|
||||
if (element.nodeName === 'BODY')break
|
||||
if (element.nodeName === 'BODY') break
|
||||
parents.push(selectors(element))
|
||||
// Stop traversing when we hit an ID
|
||||
if (element.id) break
|
||||
element = element.parentNode
|
||||
}
|
||||
return '"' + parents.reverse().join(' > ') + '". \n\n' + tagHTML
|
||||
|
|
10
test.html
10
test.html
|
@ -6,10 +6,12 @@
|
|||
</head>
|
||||
<body>
|
||||
<div class="wrapper js-pjax-container">
|
||||
<p>Label without control</p>
|
||||
<label>Label</label>
|
||||
<p>Input without label</p>
|
||||
<input type="text">
|
||||
<div id="selectors-stop-here">
|
||||
<p>Label without control</p>
|
||||
<label>Label</label>
|
||||
<p>Input without label</p>
|
||||
<input type="text">
|
||||
</div>
|
||||
<p>Button without text</p>
|
||||
<button type="button" class="abc js-menu-target" id="bbbb" aria-haspopup="true"><svg height="20" width="20"><circle cx="10" cy="10" r="10" fill="#000000"></circle></svg></button>
|
||||
<p>Link without href</p>
|
||||
|
|
Загрузка…
Ссылка в новой задаче