'alt' inside span

Go To StackoverFlow.com

-1

If 'alt' is inside 'span' would I need to change the following script

        function setNavi( $c, $i ) {
                var title = $i.attr( 'alt' );
                $('#title').text( title );

                var current = $c.triggerHandler( 'currentPosition' );
                $('#pagenumber span').text( current+1 );

            }

    $(function() {

        $('#carousel').carouFredSel({
            debug: true,
            responsive: true,
            circular: false,
            auto: true,
            prev: '#prev',
            next: '#next',
            items: {
                visible: 1,
                width: 200,
                height: '66%'
            },
            scroll: {
                onBefore: function( $oI, $nI ) {
                    setNavi( $(this), $nI );
                }
            },
                onCreate: function( $vI ) {
                    setNavi( $(this), $vI );
                }
            });

html:

<div id="carousel">
<span id="1"><img src="images/someimage.jpg"  alt="sometitle" /></span>
<span id="2"><img src="images/someimage2.jpg" alt="sometitle2" /></span>
</div>

<div id="navi">
 <p id="pagenumber">Now showing image <span></span> of 7.</p>
 <p id="title"></p>
</div>

the pagenumber is displaying correctly, but not the image title. also tried using 'title' instead of 'alt' but it still results in a blank title.

2012-04-05 23:51
by user1184254
Well, depends on what you pass as $i.. - Šime Vidas 2012-04-05 23:53


3

Yes, you would. alt is for images. Judging by the code, I'd say that the title attribute is a suitable alternative, and it will even show the same tooltip that alt does for images.

2012-04-05 23:53
by Ry-


1

You dont need to do this, its semantically incorrect. There is title field for span. Use that instead of alt.

2012-04-05 23:56
by Starx
if I use 'title' instead of 'alt', would the above script still be incorrect? I'm assuming that it's not reading title or alt because the img tag is inside a span tag. is that correct - user1184254 2012-04-06 00:34
r@user1184254, Of course you have modify it to check of title attribut - Starx 2012-04-06 00:53
aside from changing 'alt' to 'title' in the script and html, is there anything else to modify? it seems that either which way it's not displaying the title - user1184254 2012-04-06 01:04


0

If the $i object doesn't contain an alt attribute, then you can't assign it as the text of another element. It doesn't matter if the element is inside another, it depends on what parameter you're passing through your function. As Sime said, it depends what $i is.

2012-04-05 23:56
by hohner
hmm. if I understand correctly it should find the 'alt' text in the img tag and display in div "title". this is to add a caption under the image. @Starx, tried title attribute with same result (blank). update to question added - user1184254 2012-04-06 00:20
Ads