I'm having difficulty with performing a selector operation on an element variable. First I'm selecting my table element in my page using jquery.
var $popup = null;
$popup = $("#popup_List");
<div id="popup" class="popup_block">
<table id="popup_List"><tr><td>Name</td></tr></table>
</div>
I'm trying to perform a selector operation on the $popup
variable. The following does not work
$popup("tr:last").after("<tr><td>Name</td></tr");
I'd like to use the variable approach because $("#popup_List")
would have to be referenced numerous times in the code otherwise.
Projects In JavaScript & JQueryYes, it is possible to pass a variable into a jQuery attribute-contains selector. The [attribute*=value] selector is used to select each element with a specific attribute and a value containing a string.
The #id selector selects the element with the specific id. The id refers to the id attribute of an HTML element. Note: The id attribute must be unique within a document. Note: Do not start an id attribute with a number.
jQuery selectors are used to "find" (or select) HTML elements based on their name, id, classes, types, attributes, values of attributes and much more. It's based on the existing CSS Selectors, and in addition, it has some own custom selectors. All selectors in jQuery start with the dollar sign and parentheses: $().
$popup.find("tr:last").after("<tr><td>Name</td></tr");
var last = $("tr:last", popup);
just pass in the context for the jquery() method.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With