Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get element by src attribute with javascript not jquery [closed]

Tags:

javascript

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

like image 297
lbennet Avatar asked Oct 08 '13 15:10

lbennet


1 Answers

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
like image 146
prakashapkota Avatar answered Jan 01 '23 13:01

prakashapkota