4

Is there any kind of difference between the following two lines of code in JavaScript:

<button id='btn1' onclick='do_this();'>Button 1</button>;

<button id='btn1' click='do_that();'>Button 2</button>;

//some script later
function do_this()
{
    alert('this');
}

function do_that()
{
    alert('that');
}

1 Answer 1

8

onclick works in javascript, click doesn't. If you want click to work, you might need jQuery.

Sign up to request clarification or add additional context in comments.

3 Comments

Note that it should be onclick, not onClick. Attributes should be lower case.
@Eric: HTML is case-insensitive.
I said "should", not "must". It's good practice to code HTML with lower case attributes, as it makes it easy to convert into XHTML in the future.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.