Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to select parent of <script> element

Tags:

<div id="scriptparent">     <script type="text/javascript">          $( /* select above <div> from <script> ... without id and div property */ )     </script> </div> 

from the code I have a <script> block inside <div> block. I'd like to select <div> from <script> without id, class, name selectors. How can I achieve this?

like image 255
thkang Avatar asked Feb 16 '13 10:02

thkang


1 Answers

 <div id="scriptparent">         <script type="text/javascript">             var scriptTag = document.scripts[document.scripts.length - 1];             var parentTag = scriptTag.parentNode;             alert(parentTag.id);         </script>     </div> 
like image 177
Ram Khumana Avatar answered Sep 23 '22 18:09

Ram Khumana