javascript - Using Classes Instead of IDs in HTML5 -
in another post, advised not use ids, intead use classes in html forms buttons.
i'm new html5 , javascript, how use button class, , assign event handler button?
possible solution:
<!doctype html> <html> <head> <title>html button tag</title> </head> <body> <form> <button name="button" value="ok" type="button">click me</button> </form> </body> </html>
i use document.getelementbyname() , assign button handler, correct?
seriously, saying that:
ids considered bad practice quite time in html, preferred method classes
...are plain wrong! id's , classes have separate usage areas, in cases overlap. automated testing, , css, id's extremely useful. never afraid use them!
as answer question, there several options. either find element in javascript, , assign button handler, or add onclick-function, , assign directly in button tag, this:
<button ... onclick="functiontobecalled()">click me</button>
then define function you'd execute in javascript.
Comments
Post a Comment