I would like to get ID
of javascript's container, for ex:
<div id="d_17j_a">
<script type="text/javascript">
alert("<ID of javascript's container here>");
// it will alert: d_17j_a
</script>
</div>
(ID
of div is dynamic)
Thank for any suggestion !
So scripts are loaded sequentially, so you can get the parent node of a script element through:
var scripts = document.getElementsByTagName('script');
var me = scripts[scripts.length-1];
console.log('parent id', me.parentNode.id);
<script id="FindMe" type="text/javasctipt">
should work just fine using jQuery("#FindMe").parent().id
In pure javascript
document.getElementById("FindMe").parentNode.id
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With