Reputation: 75
I am creating a label at run time using jQuery. The code is :
var value="Hello";
$("#ID_listOfTopics").append('<label id="ID_item">' + value + '</label><br /><hr />');
Now I don't know how to access the text value of this particular label created at run time.
Upvotes: 0
Views: 3052
Reputation: 67505
You can access to it normally using id selector #ID_item
like following :
$("#ID_item").text();
For the click you have ro use on()
when you want to deal with fresh DOM added by javascript.
var value="Hello";
$("#ID_listOfTopics").append('<label id="ID_item">' + value + '</label><br /><hr />');
$("#ID_listOfTopics").on('click','#ID_item', function(){
alert($(this).text());
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="ID_listOfTopics"></div>
Hope this helps.
Upvotes: 2