cookies - Class Not Updating when useing case in javascript -
i don't know why class not udpated in following script using (case):
if (favorite !== null) { switch (favorite) { case 'cat': document.getelementbyid("one").classname = "favblue"; //document.getelementbyid('one').classname ='favred'; //document.createattribute('class','favred') break; case 'dog': document.getelementsbyname('dog').classname = 'favblue'; break; case 'gerbil': document.getelementsbyname('gerbil').classname = 'favyellow'; break; case 'gopher': document.getelementsbyname('gopher').classname = 'favwhite'; break; } }
please click on link in order see complete script http://jsfiddle.net/gu8u6eoc/6/
your case statement working. think should use document.getelementbyid(id)
instead of document.getelementsbyname(name)
change class values. also, applying classnames checkboxes won't change colors. should apply classnames texts instead.
according mdn, getelementsbyname
have different behavior per browser (e.g. work on elements similar id
attribute name
). also, getelementsbyname()
returns nodelist
instead of element
object.
btw, here simplified working jsfiddle. contains both usage of getelementbyid
, getelementsbyname
.
Comments
Post a Comment