Steven
Steven

Reputation: 19425

How can I get HTML element with jQuery through a variable?

Sometimes I run in to situations where I have the ID of a HTML element in a variable.
For example var activePage = frontPage. How can I use this to get the DIV element with jQuery?

Because this is not working: var div = $('#'+activePage+'footer li a').

I know I can use document.getElementById(activePage) - but I don't know how I can use this together with jQuery.

Upvotes: -1

Views: 39

Answers (1)

j08691
j08691

Reputation: 207901

You need a space in there. var div = $('#'+activePage+' footer li a'). Without the space, jQuery looks for the ID of frontPagefooter

Upvotes: 0

Related Questions