So, I have several tables that I iterate over using jQuery based on the class, but my behavior needs to change just slightly depending on the id of the element I’m in. Here’s my code:
<table id="Brokers" class="nodeTable" border=1 />
<table id="Controllers" class="nodeTable" border=1 />
<table id="Cluster-Drivers" class="nodeTable" border=1 />
jQuery(".nodeTable").html(nodeHealthTable({
Role: jQuery(this).attr("id")
}))
this ends up populating Role with the empty string. How do I access the id of the current element?
thisin your code doesn’t refer to the selected element,htmlmethod accepts a function, within the context of this functionthisrefers to the current element (jQuery useseachmethod internally).