0

I know you can do something like closest in jQuery, but I don't have that luxury here. I'm trying to obtain the span elements without a span id or class?

<table>
<tr><td><span><script>document.getElementById('The span I am in');</script></span></td></tr>
<tr><td><span><script>document.getElementById('The span I am in');</script></span></td></tr>
</table>
Rod
  • 14,529
  • 31
  • 118
  • 230
  • I don't think script elements have a perception of what element they're inside... – evolutionxbox Apr 21 '17 at 14:36
  • put an id on the span – Kyle Richardson Apr 21 '17 at 14:36
  • Marking a question a duplicate with another question that's a duplicate. _Duplicatception_ – George Apr 21 '17 at 14:37
  • @KyleRichardson, i'm sorry i misprinted...without id or class – Rod Apr 21 '17 at 14:39
  • Doesn't it make sense to bypass the duplicate and link to first question? – JCOC611 Apr 21 '17 at 14:39
  • You can get the first element of the element and check if it is a script tag or not: `function HasScript(element) { if(element.children[0].tagName == 'script') return true; else return false; }` and if the script is not the first child, check all children by a for loop – Farzin Kanzi Apr 21 '17 at 14:42
  • 2
    @JCOC611: If there's useful information, then what's the difference? And marking it as a dupe of another dupe gives a series of links that are easily followed and not available by linking to the end duplicate. –  Apr 21 '17 at 14:43
  • 1
    The question isn't unclear at all. The pseudo-code makes it very clear what the goal is. The [duplicate](http://stackoverflow.com/questions/10299846/obtain-a-reference-to-script-parent-element) covers that. – Quentin Apr 21 '17 at 14:43
  • 2
    The [duplicate](http://stackoverflow.com/questions/10299846/obtain-a-reference-to-script-parent-element) question is specifically about getting the parent element of the script, which is what this question is trying to do. While that question has been closed as a duplicate, the [target](http://stackoverflow.com/questions/403967/how-may-i-reference-the-script-tag-that-loaded-the-currently-executing-script) for it is one that is about getting the script, not the script's parent, so it isn't as close a duplicate. – Quentin Apr 21 '17 at 14:44

0 Answers0