onclick, ondblclick, onmousedown event attributes of an HTML element
event attributes of an HTML element allow users to initiate some action (as if some script is being executed) against interaction (e.g. clicking by mouse, pressing a key etc).
For all the examples, and syntax, we have used abbr element.
onclick
onclick attribute of HTML element initiates some action predefined in a script associated with it, when the user clicks on the content of the element.
Syntax
<abbr onclick="some_script | calling some script">text content</abbr>
Supported elements
All elements but APPLET, BASE, BASEFONT, BDO, BR, FONT, FRAME, FRAMESET, HEAD, HTML, IFRAME, ISINDEX, META, PARAM, SCRIPT, STYLE, TITLE.
Example of using onclick
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
<title>Example of using onclick </title>
<script type="text/javascript">
function w3r_abbr_onclick(){
alert("Thanks for visiting w3resource.");
}
</script>
</head>
<body>
<p>Even after three months of the devastating flood in Pakistan,
people are still without food, shelter or hope; <abbr title="British
Broadcasting Corporation"
onclick="w3r_abbr_onclick()">BBC</abbr> reports.</p>
</body>
</html>
Result
View this example in a separate browser window
ondblclick
Description
ondblclick attribute of HTML abbr element initiates some action predefined in a script associated with it, when user double clicks on the content of the element.
Syntax
<abbr ondblclick="some_script | calling some script">text content</abbr>
Supported elements
All elements but APPLET, BASE, BASEFONT, BDO, BR, FONT, FRAME, FRAMESET, HEAD, HTML, IFRAME, ISINDEX, META, PARAM, SCRIPT, STYLE, TITLE.
Example of using ondblclick
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
<title>Example of using ondblclick</title>
<script type="text/javascript">
function w3r_abbr_ondblclick(){
alert("Thanks for visiting w3resource.");
}
</script>
</head>
<body>
<p>Even after three months of the devastating flood in Pakistan,
people are still without food, shelter or hope; <abbr title="British
Broadcasting Corporation"
ondblclick="w3r_abbr_ondblclick()">BBC</abbr>
reports.</p>
</body>
</html>
Result
View this example in a separate browser window
Example of ondblclick attribute
onmousedown
Description
onmousedown attribute of HTML abbr element initiates some action predefined in a script associated with it, when the user presses the mouse button on the content of the element.
Syntax
<abbr onmousedown="some_script | calling some script">text content</abbr>
Supported elements
All elements but APPLET, BASE, BASEFONT, BDO, BR, FONT, FRAME, FRAMESET, HEAD, HTML, IFRAME, ISINDEX, META, PARAM, SCRIPT, STYLE, TITLE.
Example of using onmousedown
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
<title>Example of using onmousedown</title>
<script type="text/javascript">
function w3r_abbr_onmousedown(){
alert("Thanks for visiting w3resource.");
}
</script>
</head>
<body>
<p>Even after three months of the devastating flood in Pakistan,
people are still without food, shelter or hope; <abbr title="British
Broadcasting
Corporation"onmousedown="w3r_abbr_onmousedown()">BBC</abbr>
reports.</p>
</body>
</html>
Result
View this example in a separate browser window
Example of onmousedown attribute
Previous: HTML onchange attribute
Next: onmouseup, onmouseover, onmousemove, onmouseout event attributes of an HTML
Test your Programming skills with w3resource's quiz.
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://www.w3resource.com/html/attributes/HTML-event-attributes.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics