html - How to add a class to an element created with javascript -


with code create <select> element:

$('ul.category-list').each(function () {     var list = $(this),         select = $(document.createelement('select')).insertbefore($(this).hide()).change(function () {             window.location.href = $(this).val();         });     $('>li a', this).each(function () {         var option = $(document.createelement('option'))             .appendto(select)             .val(this.href)             .html($(this).html());         if ($(this).attr('class') === 'selected') {             option.attr('selected', 'selected');         }     });     list.remove(); }); 

how give <select> element id or class can control css?

html

<div class="an-element"></div> 


css

.your-class {     color: orange; } 


javascript, (using jquery library's write-less do-more methods , syntax)

$(".an-element").append("<div class='your-class'>test</div>"); 


a jsfiddle


Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -