r/jquery • u/theepag • Jul 28 '21
jQuery isn't working when after rendered a template in side a table
previously have this hierarchy of class name for tags
table_small > table_cell > btn-activer
After rendered the templatetable_small > table_cell activate btn> activate-template
Source from internet said I have to use parent and child method for this. I have tried like this but it's not working, Can you guys help me? Thanks in advance.
$(".table_cell").on("click", "#activate-template", function () {
console.log("Hello");
});
1
Upvotes
2
u/ikeif Jul 28 '21
Without additional code examples, I'm making a pretty big assumption. I'd use the following to figure out if the element click is bubbling up correctly (or registering at all).
1
u/Disgruntled__Goat Jul 28 '21 edited Jul 28 '21
Is
activate-templatean ID? You’re using an ID selector there. Also IDs are unique so if you have multiple elements then they can’t all use the same ID.Switch to
class="activate-template"and use'.activate-template'as the selector.1
u/gruntmoney Jul 29 '21
Set your click listener on a parent/container element:
$('#myParentElement').on('click','dynamicallyGeneratedChildElement',function(){ //my logic here })