3

This may be a simple question. I need to access an html element using jQuery in the following way:

var element_ID = "my" + "name" +"xyz";

Now I want to access/manipulate the element whose ID I have stored in 'element_ID' as above.

This doesn't work : $('#element_ID')

Please let me know the correct way to access the element stored 'element_ID' variable.

-Vijay

1 Answer 1

8

Just use string concatenation once more...

$('#' + element_ID)
Sign up to request clarification or add additional context in comments.

2 Comments

If you don't like building strings you can also do $(document.getElementById(element_ID)) :P
@alex Oh yeah, that's much more succinct. XP

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.