Get element by src attribute with javascript, not jquery

How to get an element by its src attribute. I use:

<script type="text/javascript" src="mysrc.js?id=1000"> 

I would need to get this element in a variable. All I know is getAttribute("src") returns src if I knew anything else besides the actual src, which is all I have. I can not use jQuery, simple JS.

thanks

+6
source share
1 answer

You can do it as follows:

 <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 
0
source

Source: https://habr.com/ru/post/955508/


All Articles