I'm attempting:
$('label[text="someValue"])
but am getting an empty set returned, most probably since text isn't an attribute.
Is it possible to select by the element's text or inner html?
Edit: :contains("someValue)
is not strict enough, since it will return any matches of someValue as a substring.
Is there a way to enumerate all the element's attributes to investigate/interrogate them during debugging/execution?
jQuery [attribute|=value] Selector The [attribute|=value] selector selects each element with a specified attribute, with a value equal to a specified string (like "en") or starting with that string followed by a hyphen (like "en-us"). Tip: This selector is often used to handle language attributes.
jQuery uses CSS-style selectors to select parts, or elements, of an HTML page. It then lets you do something with the elements using jQuery methods, or functions. To use one of these selectors, type a dollar sign and parentheses after it: $() .
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.
Which is the correct jQuery selector statement to select all <div> elements? Explanation: The statement $("div") is the correct syntax to select all <div> elements.
You can select them all and then filter down to a smaller subset by using filter
:
$('label').filter(function () {
return $(this).text() === "someValue";
});
Tested this:
$.each($("#form label"), function() {
var nodes = this.attributes;
for(var i=0; i<nodes.length; i++)
{
alert(nodes[i].nodeName);
alert(nodes[i].nodeValue);
}
});
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