TeaCupApp
TeaCupApp

Reputation: 11452

Is it possible to call a jquery function on a variable?

I am trying to call a query function call on a variable, but it is not working. Is there any way around this?

$(function() {
      $variableName = '#fanpagePanelHeader';
      $(variableName).click( function()
           {
             $("#videoAcco").click();
           }
      );
});

Upvotes: 0

Views: 1361

Answers (2)

Blender
Blender

Reputation: 298106

Your variable is named $variableName, so call the jQuery function on the variable:

$($variableName).click(...

The dollar sign is a valid character in a variable name but don't think it's jQuery-specific. It's just another character.

Upvotes: 4

Cassie Smith
Cassie Smith

Reputation: 501

I'm new to jQuery, but shouldn't it be:

var variableName = '#fanpagePanelHeader';

Upvotes: 2

Related Questions