How to get the element by its src attribute. I'm using:
<script type="text/javascript" src="mysrc.js?id=1000">
I would need to get that element on a variable. All I know is getAttribute("src")
returns the src if I knew anything else besides the actual src whcih is all I have. I can't use jQuery, plain JS.
Thanks
You can do like this
<script id="mysrc" type="text/javascript" src="mysrc.js?id=1000">
var src = document.getElementById("mysrc").getAttribute("src")
console.log(src.split('id=')[1]); //1000
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