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

flask-mail AttributeError: 'function' object has no attribute 'send'

python flask flask-mail

I am trying to use flask.ext.mail to send email, however I am getting the following error. I followed a number of tutorials and they all seem to be doing the same thing, I have been looking around ...

WHM/Cpanel API Cron::listcron request using cURL

php curl cpanel whm whmcs

I'm using the code below to get a cron list but only thing I get is a blank page. Also when I replace port 2087 by 2083 the output is {"data":{"reason":"Access denied","result":"0"},"type":"text"} ...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.