Can't set the class attribute?

These lines in jquery make 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 name is" classname ":

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

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

help me please...

+4
source share
4 answers

Use

 {'class': 'dropDown'} 

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

+9
source

Try:

 { "class": "dropDown" } 

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

+11
source

The easiest way is to use the following:

 var dropDown = $('<ul>').addClass('dropDown'); 

Use your own jQuery methods, they are made for this. It is also much more readable.

+3
source
 {'class':'dropDown'} 

should work in all browsers. Alternatively, you can try

 dropDown.addClass("dropDown"); 

Good luck

+1
source

Source: https://habr.com/ru/post/1381861/


All Articles