How to check class name using javascript?? I am using this statement.. if (document.getElementByClass("expandable")
but it give me error.. "Object doesn't support this property or method"
How to check class name using javascript?? I am using this statement.. if (document.getElementByClass("expandable")
but it give me error.. "Object doesn't support this property or method"
Because you just made that method up!
You want document.getElementsByClassName: https://developer.mozilla.org/en/DOM/document.getElementsByClassName
There is no function document.getElementByClass. Either check for the property .className of potential objects, or use a higher level framework which implements this (Such as jquery). This is the syntax with jquery:
$(".expandable")
Via pure javascript:
You can use the getElementsByClassName from this question
With jQuery, this is lot more simple, use the class selector:
$(".className)
There is no function like getElementByClass.
You have to use document.getElementsByClassName; it will return an array
so you have to use loop to get values.
But MSIE will not support this function so you have to check your class name like:
((document.getElementsByTagName("div"))[i].className)=="yourclassname"