Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery attribute selectors: How to query for an attribute with a custom namespace

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.)

like image 691
Sebastian Rittau Avatar asked Sep 18 '08 10:09

Sebastian Rittau


1 Answers

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.'); }); 
like image 78
Devon Avatar answered Sep 22 '22 00:09

Devon