I have 3 tables - Table1 Table2 and Table3
I want to change this $("tr").filter to only effect Table2
Is this correct?
$("#Table2 tr").filter or is there any other way to do so?
I have 3 tables - Table1 Table2 and Table3
I want to change this $("tr").filter to only effect Table2
Is this correct?
$("#Table2 tr").filter or is there any other way to do so?
Sounds right to me, or paste some html so we can see what you're dealing with.
If Table2 is the ID of the table then yes. Jquery uses CSS selectors, so to be more explicit you could try:
$("table#Table2 tr").filter
The best way to do it is using:
$('tr', '#Table2')
As noted by the documentation, the 2nd argument of the $()
function is a context selector that tells it where to look. By default that is the entire document, but you can specify something else, like a table:
By default, if no context is specified, $() looks for DOM elements within the context of the current HTML document. If you do specify a context, such as a DOM element or jQuery object, the expression will be matched against the contents of that context.
Although what you have will work, the above is the optimal way of doing it. Speed difference for your average use case will be insignificant, though. I just prefer specifying the context whenever possible.