Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Relying on :eq() is tough! It is difficult to reliably re-select out of a DOM that is dynamic. Sure it may work on very static pages, but things are only getting more dynamic every day. You might consider changing strategy a little bit. Try using a smarter more flexible selector. Perhaps pop in some javascript like so:</p> <pre><code>predictCss = function(s, noid, noclass, noarrow) { var path, node = s; var psep = noarrow ? ' ' : ' &gt; '; if (s.length != 1) return path; //throw 'Requires one element.'; while (node.length) { var realNode = node[0]; var name = (realNode.localName || realNode.tagName || realNode.nodeName); if (!name || name == '#document') break; name = name.toLowerCase(); if(node.parent().children(name).length &gt; 1){ if (realNode.id &amp;&amp; !noid) { try { var idtest = $(name + '#' + realNode.id); if (idtest.length == 1) return name + '#' + realNode.id + (path ? '&gt;' + path : ''); } catch (ex) {} // just ignore the exception, it was a bad ID } else if (realNode.className &amp;&amp; !noclass) { name += '.' + realNode.className.split(/\s+/).join('.'); } } var parent = node.parent(); if (name[name.length - 1] == '.') { name = name.substring(0, name.length - 1); } siblings = parent.children(name); //// If you really want to use eq: //if (siblings.length &gt; 1) name += ':eq(' + siblings.index(node) + ')'; path = name + (path ? psep + path : ''); node = parent; } return path } </code></pre> <p>And use it to generate a variety of selectors:</p> <pre><code>var elem = $('#someelement'); var epath = self.model.util.predictCss(elem, true, true, false); var epathclass = self.model.util.predictCss(elem, true, false, false); var epathclassid = self.model.util.predictCss(elem, false, false, false); </code></pre> <p>Then use each:</p> <pre><code>var relem= $(epathclassid); if(relem.length === 0){ relem = $(epathclass); if(relem.length === 0){ relem = $(epath); } } </code></pre> <p>And if your best selector still comes out with more than one element, you'll have to get creative in how you match a dom element - perhaps levenshtein or perhaps there is some specific text, or you can fallback to eq. Hope that helps!</p> <p>Btw, I assumed you have jQuery - due to the sizzle reference. You could inject the above in a self-executing anonymous function in a script tag appended to the last child of body for example.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload