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>");
Comments
Post a Comment