Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't set "class" attribute?

These lines in jquery making me bad:

var selectBoxContainer = $('<div>',{width: select.outerWidth(), className:'styledSelect', html:'<div class="selectBox"></div>'});
var dropDown = $('<ul>',{className:'dropDown'});

It should set the class attribute "class="styledselect" in the output, but the attribute's name is "classname":

<div classname="styledSelect">
    <ul classname="dropDown" style="display: none;">...</ul>
</div>

when I change it simply to {class:'dropDown'} ist works in firefox, but not in other browsers.

help please...

like image 478
Thomas Avatar asked Nov 28 '22 09:11

Thomas


2 Answers

Try:

{ "class": "dropDown" }

or add .addClass("drowDown") to the end.

like image 157
Richard Dalton Avatar answered Dec 19 '22 18:12

Richard Dalton


Use

{'class': 'dropDown'}

class is a future reserved word in JavaScript, so you must specify it as a string inside object literals for some browsers, notably IE 8 and lower.

like image 30
Andy E Avatar answered Dec 19 '22 16:12

Andy E