css - Get button element and Style button using JavaScript -
<input type="submit" name="$submit$0" value="log in">
how element id/tag/class above type of button? want style too.
is correct?
if (document.getelementsbyclassname("submit") !== undefined || document.getelementsbyclassname("submit") !== null) { var ele = document.getelementsbyclassname("submit"); (i = 0; < ele.length; i++) { ele[i].style.color = "#6699ff"; ele[i].style.padding = "0px"; ele[i].style.height = "10px"; ele[i].style.width = "30px"; } }
or?
if (document.getelementsbytagname("submit") !== undefined || document.getelementsbytagname("submit") !== null) { var ele = document.getelementsbytagname("submit")[0]; ele.style.color = "#6699ff"; ele.style.padding = "0px"; ele.style.height = "10px"; ele.style.width = "30px"; }
getelementbyid won't work here. in advance!
methods document.getelementsbyclassname
document.getelementsbytagname
never return undefined
or null
. result returned htmlcollection should check if collection empty or not. use length
property:
if (document.getelementsbyclassname("submit").length) { // ... }
note in case, should checking type attribute of button, not it's class or tag name.
for method convenient document.queryselectorall
(collection):
if (document.queryselectorall('[type=submit]').length) {}
or if want check 1 button use document.queryselector
(single element):
if (document.queryselector('[type=submit]')) {}
Comments
Post a Comment