0

Been trying everything all day to get this to work with no luck.

I want to use the title attribute from an li element as a string inside of a completely separate span element.

Here is my code:

<script type="text/javascript">
    $(document).ready(function(){

    });
</script>
<div id="slider">
  <ul>
    <li class="slide" title="Careers">
        <img src="large-image-1.jpg" alt="Large Image 1" /> </li>
  </ul>
</div>
<div id="slide-thumbs">
  <ul>
    <li><img src="thumb-image-1.jpg" alt="Thumbnail for Large Image 1" />
        <span class="thumb-caption"><!-- need title attribute above reading "Careers" to go here --></span>
  </ul>
</div>

I feel like I'm missing something easy here. I can only use Javascript to do this with the script I'm working with. PHP is not an option. Any help would be very much appreciated.

Thank you, Justin.

3 Answers 3

3
var title = $('.slide').attr('title');
$('span').html(title);
Sign up to request clarification or add additional context in comments.

4 Comments

or your site doesn't support jquery
Hey, it should be running jQuery. Here's the actual link: 72.10.171.242/~monteith Maybe you can see what's going on from there. I actually had to add the span tag in a .js file where the thumbnail code is located. So it's displaying from there. I appreciate the help guys, thanks a lot.
Just noticed: there's no closing </li> tag toward the bottom of your code. Don't know if that's causing a problem...
No, that was just simplified code to better explain the real situation.
1

The JS should work fine, but something to consider is you could do this with pure CSS and avoid the extra markup. Just display the title attribute using a pseudo-element and position it where you like:

.slide:before {
    content: attr(title);
    position: absolute;
    display: block;
}

Since the title is already displaying on the page and you're not generating anything else in addition to it, no reason for the extra element

Comments

0

If there is more than one slide, better use:

$('.thumb-caption').each(function(i) {
    $(this).html($('.slide').eq(i).attr('title'));
});

3 Comments

No luck with this either. Still an empty span tag. 72.10.171.242/~monteith
You're doing sth wrong - have a look at the quick demo: jsbin.com/ibuhoc/1
I applied your code exactly and the span tag is still empty. Here is the actual example of what I'm trying to do. 72.10.171.242/~monteith - The javascript is on line 198, the slides are on lines 271 and 296 (What's New and Careers). The thumbnails and the span tag I'm trying to populate come from a .js file called jquery.themepunch.revolution.min.js

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.