tags:

views:

45

answers:

2

here my code-

---
<ul>
                <li id="d1"><a href="images/soluinfo1.jpg"><img src="images/menu_hosp.jpg" border="0"></a></li>
                <li id="d2"><a href="images/soluinfo2.jpg"><img src="images/menu_edu.jpg" border="0"></a></li>
                <li id="d3"><a href="images/soluinfo3.jpg"><img src="images/menu_enter.jpg" border="0"></a></li>
                <li id="d4"><a href="images/soluinfo4.jpg"><img src="images/menu_retail.jpg" border="0"></a></li>
                <li id="d5"><a href="images/soluinfo5.jpg"><img src="images/menu_health.jpg" border="0"></a></li>
                <li id="d6"><a href="images/soluinfo6.jpg"><img src="images/menu_real.jpg" border="0"></a></li>
                <li id="d7"><a href="images/soluinfo7.jpg"><img src="images/menu_tel.jpg" border="0"></a></li>
            </ul>

Jquery function-

function imgchange()
    {
        $('.smenu li').mouseover( function(){
        var src = $(this).find('a').attr('href');
        $('.hbg').css('background-image', 'url(' + src + ')');
        });     
    }

this is working fine background image is getting changed but I want to set the title attribute of the image too, so that when user goes over there tooltip shoud come.like-
<img src="---" title="my tootip info" >

+3  A: 
function imgchange()
    {
        $('.smenu li').mouseover( function(){
            var src = $(this).find('a').attr('href');
            $('.hbg').css('background-image', 'url(' + src + ')');

            $('.hbg').attr('title', 'my tootip info'); // <= DO THIS

        });     
    }

EDIT
I suppose you are making some sort of slideshow, and $('.hbg') is the slide view port.
So you should set the title for this element. I edited the code to reflect this.

clyfe
I think he do NOT want to change the title of the link as you did. He want to change the title of background image of the element whose class is 'hbg'.
Kai
please correct that. last line in OP's question is `<img src="---" title="my tootip info" >`
Reigel
@clyfe i think u got confused `<a href="images/soluinfo1.jpg"><img src="images/menu_hosp.jpg" border="0">` I want to set title for `soluinfo1.jpg` not for `menu_hosp.jpg`
nectar
Checked, all ok now.
clyfe
A: 

Short answer: you can't do that using CSS.

The title attribute is supposed to convey information in case the image is not there and cannot be set in CSS. It needs to be part of the HTML mark-up.

Ciaran Archer
Almost everything is possible with javascript, but you need to know how.
Bakhtiyor
@Ciaran,I think you mixed up with "alt".. "title" can be anything as long as it specifies extra information about the image
Kai
Did I really deserve a -1 markdown on this? @Bakhtiyor - I never said it was impossible using Javascript, just using CSS.
Ciaran Archer
@Ciarán. I just commented on your answer. I didn't down-vote or up-vote for you response. I think it is somebody else. I am really sorry for that.
Bakhtiyor
@Ciarán Archer: I wasn't the vote downer either but when I first saw your answer I wondered why you suddenly bought CSS up. Might be that the question originally asked about CSS solutions but I can imagine somebody might think that an answer which is "You can't do it with this technology" is not useful unless somebody specifically says that is the only technology available.
Chris
Ciaran Archer
@Ciarán Archer: looks like the original question has been edited then. And looks like somebody has either undone their downvote or you got a compensating upvote. :) I think I saw somebody say somewhere that you should never downvote without a reason which I think is a pretty good rule most of the time.
Chris