javascript - How to find dynamically added element by data attribute using jQuery? -


there element dynamically applied data attribute this

var tr = $('<tr>'); tr.data('template_id', 5); table.find('tbody').append(tr); 

here have our tr on table.
...
here want find our newly added tr data attribute

var tr = table.find('[data-template_id="5"]'); console.log(tr) // tr.length = 0; 

unfortunately, have no found tr way.
why getting result?

the issue have data-* attributes added via jquery stored in internal cache. not available attributes in dom. in mind, can use filter() achieve require:

var $tr = table.find('tr').filter(function() {     return $(this).data('template_id') == 5; }); console.log($tr.length); 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -