Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
160
rated 0 times [  165] [ 5]  / answers: 1 / hits: 17553  / 10 Years ago, mon, july 21, 2014, 12:00:00

Small part of my html code :



<div class=text-center>

<div class=btn-group>
<button type=button class=btn btn-default dropdown-toggle data-toggle=dropdown>
Platforms <span class=caret></span>
</button>
<ul class=dropdown-menu role=menu id = buttonsPlace>
</ul>

</div>


In my js file :



for (i = 0; i < platformList.length; i++) {
var li = $(<li/> , { id : plat+i,class : dropdown text : platformList[i] } )
//var text = document.createTextNode(platformList[i]);
//li.appendChild(text);
//btn.data(platform, platformList[i] );
$(#buttonsPlace).append(li);
console.log(hiding);
$(#plat + i).hide();
}


However the menu is appearing but the menu items are not. where am i going wrong


More From » jquery

 Answers
52

Try This



$(function() {
var change = function( txt ) {
$(#ID).append( '<li>' + txt + '</li>' );
};
change(this is the first change);
change(this is the second change);
});


Demo



For Li Click



$(ul).on('click', 'li', function () {
var id = this.id;
//play with the id
});

[#70128] Friday, July 18, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
deonkalvinw

Total Points: 409
Total Questions: 96
Total Answers: 89

Location: Saint Pierre and Miquelon
Member since Sun, Nov 27, 2022
2 Years ago
deonkalvinw questions
Sun, Feb 6, 22, 00:00, 2 Years ago
Tue, Dec 28, 21, 00:00, 2 Years ago
Sun, Aug 22, 21, 00:00, 3 Years ago
Sun, Mar 7, 21, 00:00, 3 Years ago
;