From jquery back to JavaScript

I need a pure JavaScript equivalent of this Jquery code: because the use of libraries isnt allowed in my current project,

File handler.js

$(document).ready(function(){

 $("#some_button").click(function(){

  alert('ok. works');

 });

});

File index.html

<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="handler.js"></script>
<head>
<body>
<button id="some_button">Btn</button>
</body>

</html>

Answers


Put this in your handler.js file:

window.onload = function() {
  document.getElementById('some_button').addEventListener('click',
    function() {
       alert('ok. works');
    }, true);
};

NB: this won't work on older IE versions that don't support addEventListener. You could be lazy and use the DOM0 element.onclick method instead.


 function buttonClick() {
     alert('ok. works');
}

File index.html

<!DOCTYPE html>
<html>
<head>

<head>
<body>
<button id="some_button" onclick="buttonClick()">Btn</button>
</body>

</html>

Need Your Help

How to get date from android calendar?

java android date calendar

Please, help me get date from calendar. Idea is that user must choose date. After that the date has returned to the main Actiity.

JavaScript: Extract one element out of an array that is created after php json encode

php arrays multidimensional-array

var Array = [["1","123","3","3","3","20"],["2","253","2","2","2","15"],["3","222","4","4","4","15"],["4","353","5","5","5","15"]];