Is it possible to set some data by using the jQuery data method and then later query it? Something like ... find all elements with data foo == true?
The jQuery #id selector uses the id attribute of an HTML tag to find the specific element. An id should be unique within a page, so you should use the #id selector when you want to find a single, unique element.
Use the querySelector method to get an element by data attribute, e.g. document. querySelector('[data-id="box1"]') . The querySelector method returns the first element that matches the provided selector or null if no element matches the selector in the document.
Right-click the new target and select Properties. The attributes of the target open in a new pane. Select an Adapter from the drop-down menu to specify the target type. Note: Only data target types that are configured on the server and supported by DataMigrator will appear.
How to select an element by name with jQuery? The JavaScript getElementsByName() method can be used to select the required element and this can be passed to a jQuery function to use it further as a jQuery object.
You can use .filter()
to select the elements you want, like this:
$("someSelector").filter(function() { return $.data(this, "foo"); });
In this case since you're checking a boolean it's very simple, for checking against a value just add the comparison, like this:
$("someSelector").filter(function() { return $.data(this, "foo") == "value"; });
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