Jquery - How to find an element using class and attribute

I am trying to figure out the most efficient way to find my element. Following i smy structure:

<div class="a" customattrib="2">

in order to find this element can I do something like :

$("div.a [customattrib='2']")

This does not seem to work, is there another way to do this?

Without the class I am able to get the value but I do not think this is efficient enough for my structure:

$("div [customattrib='2']")

Answers


Remove the space:

$("div.a[customattrib='2']")

By putting in the space, you're making it into a descendant selector which finds all elements that match [customattrib='2'] and are inside an element that matches div.a.


Need Your Help

Getting fb.me URL

facebook url hyperlink short

How do I go about either making, or retrieving facebook short url's (fb.me) from a page, profile, event etc? I want to update my url shortener site - but if the user links to a facebook page I want...

List all virtualenv

virtualenv virtualenvwrapper virtualenv-commands

In virtualenvwrapper, is there a simple way to list all virtualenv on my machine?