html - How to get class name through JavaScript? -


how class name through javascript using element name classic html.

like:

<input name="xxx" class="checkbox" onchange="checkonchange()"        type="checkbox" checked="" value="y"> 

i want check fields has class name "checkbox" .

how can solve this? please me.

there lot of solutions. first access element classname use code :

element.classname 

next if want test if classname exist inside element list, can test indexof have false positive. class "foo" not present in following element.classname : "foobar foobuzz"

best way use regexp :

checkifelementhasclassname(element, classname) {    return (new regexp('^|\\s' + classname + '\\s|$')).test(element.classname); } 

Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -