C_K
C_K

Reputation: 1243

Click Event not binding?

I have a menu, I'm trying to change the background image of a div elsewhere in the html to the href of the link clicked. It's odd because i have a script that does almost the same thing, on mouseover. I tried to tweak it to work for this, but to no avail.

    $(".IG_Nav_List a").live('click',function(){ 
        var src = $(this).attr("href");
        $('.Background').css('background-image', 'url(' + src + ')'); 
    });

    ////////////////

   <div class="Background"></div>

    <ul class="IG_Nav_List">
       <li><a href="Surface/A.jpg" onclick="return false;">AAAA</a></li>
       <li><a href="Surface/B.jpg" onclick="return false;">BBBB</a></li>
       <li><a href="Surface/C.jpg" onclick="return false;">CCCC</a></li>
    </ul>

Upvotes: 0

Views: 308

Answers (3)

Sang Suantak
Sang Suantak

Reputation: 5265

For the first part of your code, look at this line:

$('.Background').css('background-image', 'url(+src+)'); 

This should be

$('.Background').css('background-image', 'url(' + src + ')'); 

Upvotes: 0

Lucas d. Prim
Lucas d. Prim

Reputation: 787

I don't see the element with the Background class but..

Here's a catch:

$('.Background').css('background-image', 'url(+src+)'); 

should be

$('.Background').css('background-image', 'url(' + src + ')');

Upvotes: 0

ChrisThompson
ChrisThompson

Reputation: 2008

for starters:

'url(+src+)'

should probably be

'url('+src+')'

Upvotes: 5

Related Questions