1

I don't find an answer for my problem. I think it's a very small one, but I have some knots in my brain currently.

I need <li> elements for styling but the function to add the alt attribute to a specific element ( #c11 ) does not appear to work when using &lt;li&gt; before &lt;img&gt; while it seems fine without.

Can you help me ?

Here is my JS:

$(document).ready(function() { 

$('#slideshow1').cycle({ 
    fx:      'scrollHorz', 
    auto: false,
    before:   onBefore,
    prev:    '#prev',
    next:    '#next',
    timeout:  0,
    sync: 1,
    speed: '100',
    pagerAnchorBuilder: pagerFactory,
    after:     function() {
    $('#c1').html(this.alt);
    }
}); 

var slidesAdded = false; 
function onBefore(curr, next, opts) { 
    if (!opts.addSlide || slidesAdded) 
        return; 
    opts.addSlide('<li><img src="loadimages/1.jpg" width="800" height="560"  alt="Beach 1" /></li>'); 
    opts.addSlide('<li><img src="loadimages/2.jpg" width="800" height="560"  alt="Beach 2" /></li>'); 
    opts.addSlide('<li><img src="loadimages/3.jpg" width="800" height="560"  alt="Beach 3" /></li>'); 
    opts.addSlide('<li><img src="loadimages/4.jpg" width="800" height="560"  alt="Beach 4" /></li>'); 
    slidesAdded = true; 
}; 
function pagerFactory(idx, slide) {
    var s = idx > 2 ? ' style="display:none"' : '';
    return '<li'+s+'><a href="#">'+(idx+1)+'</a></li>';
};

and here’s the html:

 <div style="text-align:center;margin:auto;width:300px">
    <a href="#"><span id="prev">Prev</span></a> 
    <a href="#"><span id="next">Next</span></a>
</div>

<div id="slideshow1" class="pics"> 
 <li><img src="loadimages/1.jpg" width="800" height="560" alt="Beach 1"  /></li>
 <li><img src="loadimages/4.jpg" width="800" height="500" alt="Beach 2" /> </li>

</div> 
yadutaf
  • 6,840
  • 1
  • 37
  • 48

1 Answers1

0

Using jQuery it's possible to style the Alt tag inside a figure tag's figcaption. Here's a fiddle (https://jsfiddle.net/0Lqxb4cp/) which might look something like this:

.img-fluid { width: 100%; }
figure { display:block; position: relative; }

figcaption { display: block; }

Using this HTML:

<figure>
    <img class="img-fluid" src="image.png" alt="This content will be appended inside the Figure Caption tag!">
</figure>`

Followed by this jQuery:

<script src="js/jquery.js"></script>  
<script>
$('img', 'figure').each(function() {
        $(this).parent().append('<figcaption>' + this.alt + '</figcaption>');
    });
</script>
Scott Phillips
  • 177
  • 2
  • 10