Leon Gaban
Leon Gaban

Reputation: 39018

How to retrieve dynamically created html tag value in jQuery?

So I am able to create a tag name on the fly and add it to my html

$('#'+modal_ID).attr('tag', roleName);

Will create the following html div:

<div class="modal simplemodal-data" id="modal-1" style="" tag="Actor">...

Now my question is, how do I retrieve that tag information to use elsewhere?

var saveTagVar = $('#'+modal_ID).getElementsByTagName; //Trying something like this

Upvotes: 0

Views: 114

Answers (3)

Karl-Andr&#233; Gagnon
Karl-Andr&#233; Gagnon

Reputation: 33870

getElementsByTagName Search elements with the tag indicated, but in this case, tags are nodes like div ul, etc.

If you want the 'tag value, use .attr('tag') It will get the attribute value of the selected node.

Upvotes: 0

Sharlike
Sharlike

Reputation: 1789

Is this what you are looking for?

var tag = $('#'+modal_ID).attr('tag');
console.log(tag); //'Actor'

Upvotes: 2

tymeJV
tymeJV

Reputation: 104775

This will give you the tag attr

var saveTagVar = $('#'+modal_ID).attr("tag");

Upvotes: 2

Related Questions