anonymous anonymous - 1 year ago 98
jQuery Question

jQuery selectors with variables

How to mix variables with selectors?

I have ID variable.

I want to select image with this id from div #one.

jQuery('#one img .id')
is the selector. I've tried
$('#one img .'+id)
but doesn't work.

Answer Source

Edit: Based on your comment below, you would use this:

$('#one img.'+id)

In your question you have a space between the img & the .class, I've simply removed that so you get img.className or img.'+className

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download