Suppose I have a simple XHTML document that uses a custom namespace for attributes:
<html xmlns="..." xmlns:custom="http://www.example.com/ns"> ... <div class="foo" custom:attr="bla"/> ... </html>
How do I match each element that has a certain custom attribute using jQuery? Using
$("div[custom:attr]")
does not work. (Tried with Firefox only, so far.)
jQuery does not support custom namespaces directly, but you can find the divs you are looking for by using filter function.
// find all divs that have custom:attr $('div').filter(function() { return $(this).attr('custom:attr'); }).each(function() { // matched a div with custom::attr $(this).html('I was found.'); });
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