Web Design   // jQuery

Using Variables in JQuery Selectors

If you want to use variables in combination with CSS-style selectors like so:

$("#navigation a.myHomePage, " + logo).hover(function() {
$("li.home").addClass("homeRoll");
}, (function() {
$("li.home").removeClass("homeRoll");
});

Make sure your variable homePageImage is written as a string:

var homePageImage = "#logo"

not an object:

var homePageImage = $("#logo")

or it won’t work.

Tags: ,

2 Responses to “Using Variables in JQuery Selectors”

  1. Polprav says:

    Hello from Russia!
    Can I quote a post in your blog with the link to you?

  2. admin says:

    Absolutely! As long as I didn’t say anything incriminating :)

Leave a Reply

Without ambition one starts nothing. Without work one finishes nothing. The prize will not be sent to you.
--Ralph Waldo Emerson

I'm a web designer and writer based out of Nashville, TN, where I live with my husband, step-daughter, and chihuahua.

moonkatcreations at gmail dot com