anonymous anonymous - 4 months ago 8
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

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

Comments