tags:

views:

89

answers:

3

If I use the following selector I get no results

$(".itemSearchModule .cmsItemList[rel='myRelValue']")

for the following html snippet

<div class="itemSearchModule">
    <ul class="cmsItemList" rel="myRelValue">
      <li>something</li>
    </ul>
</div>

MISTAKE I was using firebug to debug the code and it seems that using that code in firebugs watch window is what is causing it to break

A: 

It works :) You just need to "call" it this way:

$('.itemSearchModule .cmsItemList[rel=myRelValue]')

Check the docs on jQuery.com

Also, don't forget to call the selector after page load

$(document).ready(function () { put_selector_here });

Bogdan Constantinescu
I dont see what difference your code is?! Im actually passing a string variable to it (code simplified for question), and the docs say quotes are optional
tigermain
I am calling it in a ready statement
tigermain
A: 

Well, now you changed your question. Delete this post.

smack0007
+1  A: 

The rel attribute is only allowed for A and LINK elements as it describes the relation between two documents, the current document and the document referenced in the href attribute. You should better use the class or id attribute for your purpose.

Gumbo
It will still work with jQuery, although not technically valid markup.
smack0007
But surely in XHTML I can have any attribute on any element, if I have a bespoke one [myattr='test'] it will work, just why is REL blocked?!
tigermain
Technically you can't have the rel tag. Run it through a validator and you'll get an error.
smack0007
but smack0007 the whole point is, it doesnt!
tigermain
I understand that it doesn't work for you. But look at some of the comments to your question. I do this all the time as well.
smack0007
Regardless of whether it's valid you should still be able to set attr('rel') and retrieve it using the selector syntax as then there is no invalid markup anywhere, only an attribute stored against the element in the DOM!
tags2k