Matthew,

.css() doesn't return a class Name.  In your example it might return
the background image url. Here's an example console dump from a banner
of a site I work on:

>>> var foo = $("#banner").css('background-image');
>>> foo
"url(http://www.mysite.com/img/homebanner.jpg)"

You can try something like this:

var className = $(this).attr('class')

and then use addClass, but that is assuming the matched element(s) has
a class. I can see circumstances where that will return more than one
class or could result in unexpected results.

I don't know if there is a way to iterate over each of a jQuery
objects CSS properties. If there is you could conceivably read each
then set the css attribute of the target div.

On Sep 3, 2:35 pm, Matthew <[EMAIL PROTECTED]> wrote:
> Hi, I just started playing with jquery yesterday and I'm interested in
> assigning the css class of an <a> element to a variable and then
> applying that class to a div in another section.
>
> While I've been looking through multiple tutorials and searching on
> the discussion board I haven't seen it.
>
> i.e.
> $("#exampleClass a").click(function()
>      {
>      var className = $(this).css("background-image");
>      $("#TargetDiv").addClass(className);              // where
> className is the variable
>      });
>
> });
>
> Any guidance/help would be much appreciated!

Reply via email to