Web DesignjQuery

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

“Fear is the path to the dark side. Fear leads to anger. Anger leads to hate. Hate leads to suffering”

—Master Yoda

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