How to access multiple html file elements from same external javascript file -


this want know if can access multiple html file elements same external javascript file.

scenario:

one.html

<div id="one" onclick="onediv"></div> 

two.html

<div id="two" onclick="twodiv"></div> 

script.js

function onediv(){     var instance = document.getelementbyid("one"); }   function twodiv(){     var instance = document.getelementbyid("two"); } 

the question more specific if ask one js file multiple pages

if understood question correctly, want have single function clicked div.

you can achieve this keyword. this references dom object event triggered in case.

for example if want alert div's content can this:

<div id='one' onclick='shout()'>foo</div> <div id='two' onclick='shout()'>bar</div>  <script type='text/javascript'>     function shout(){         alert(this.innerhtml());     } </script> 

Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -