0

I want to know about all the attributes of HTML element in which we can write javascript code as value. Share if you know any of them.

eg.

<input type="button" onclick="if(fun1(2)){fun2();}" value="Button"/>

I want to know all the attributes like as onclick in which I can write Javascript code without using <script> tag.

3
  • You can write javascript in (almost?) any attribute. jsfiddle.net/89j63245 But for it to be executed... Commented Oct 31, 2017 at 11:40
  • But for this I need to use eval but for onclick I don't need that can we have more examples like onlick, onload etc. Commented Nov 1, 2017 at 4:54
  • well for onclick you need a click event, and for onload you need the Element to be able to load a resource and/or have a load event triggerer. Same boat. But I'll quit my pedantry for a minute, what you seem to want is called event attributes, the answer below offers quite a long list of these, but it's not even exhaustive since you could probably write your own with CustomElements. But anyway, these event attributes should not be used, instead use event listeners. Commented Nov 1, 2017 at 5:00

1 Answer 1

2

i think this article will help you. These are the global event attributes that can be added to HTML elements to define event actions

https://www.w3schools.com/tags/ref_eventattributes.asp1

Window Event Attributes

onafterprint
onbeforeprint
onbeforeunload
onerror
onhashchange
onload
onmessage
onoffline
ononline
onpagehide
onpageshow
onpopstate
onresize
onstorage
onunload

Form Events

onblur
onchange
oncontextmenu
onfocus
oninput
oninvalid
onreset
onsearch
onselect
onsubmit

Keyboard Events

onkeydown
onkeypress
onkeyup 

Mouse Events

onclick
ondblclick
onmousedown
onmousemove
onmouseout
onmouseover
onmouseup
onwheel
onwheel

Drag Events

ondrag
ondragend
ondragenter
ondragleave
ondragover
ondragstart
ondrop
onscroll

Clipboard Events

oncopy
oncut
onpaste

Media Events

onabort
oncanplay
oncanplaythrough
oncuechange
ondurationchange
onemptied
onended
onerror
onloadeddata
onloadedmetadata
onloadstart
onpause
onplay
onplaying
onprogress
onratechange
onseeked    
onseeking
onstalled
onsuspend
ontimeupdate
onvolumechange
onwaiting

Misc Events

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

7 Comments

While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review
@manish i have added attributes to the answer. sorry for the mistake i did. please remove the downvote if you can. i only tried to help
I have not downvoted the question, merely actioned it in the close queue. Do note that the question is not only too broad, it can be easily looked up via a web search. It does not deserve an answer of its own. A simple comment under the question, providing the link to the relevant page would suffice. Trying to answer poor questions encourages users to post more bad quality questions.
Thanks @pavithrarox for posting answer.
@ShivamSharma, the primary purpose of StackOverflow (SO) is to catalog solutions to programming problems in general so that multiple programmers can benefit from them. SO is not for soliciting one-to-one help (be careful of being tagged as a help vampire). Enough poor quality questions may even lead to a question ban. It is also important to discourage users from trying to answer low-quality questions as enough poor answers may lead to answer ban for them as well.
|

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.