I am creating a system of displaying link information in an interactive way using html attributes, and jQuery to move some of the HTML around. I am stuck trying to append a title attribute to a div. I’ve never done this with an attribute and am hitting some walls.
It’s hard to explain, but you will see what I am after when you see the JS.
http://jsfiddle.net/KvAwa/
thx for any help in advance
The HTML
<div id="navtool">
<ul id="menu">
<li id="1">
<a href="location1.html" title="this is the decription1">This is the link1</a>
</li>
<li id="2">
<a href="location2.html" title="this is the decription2">This is the link2</a>
</li>
<li id="3">
<a href="location3.html" title="this is the decription3">This is the link3</a>
</li>
</ul>
</div>
<a href="#" class="prev nav">prev</a>
<a href="#" class="next nav">next</a>
<div id="linkdesciption"></div>
<a href="#" id="execute">Execute link</a>
The JS
// Cycles Menu
$('#menu > li:first').addClass('active');
$('.next').click(function(){
$('.active').next().addClass('active').prev().removeClass('active');
$('#menu > li:last').after($('#menu > li:first'));
});
$('.prev').click(function(){
$('.active').prev().addClass('active').next().removeClass('active');
$('#menu > li:first').before($('#menu > li:last'));
});
// Collects the link
var executeLink = $('#menu > li.active > a').attr("href");
$('#execute').attr("href", executeLink);
$('#execute').click(function(){
alert(executeLink);
});
// Collects title and inject into description
$('.nav').click(function(){
var description = $('.active > a').attr('title');
$(description).appendTo('#linkdesciption');
});
I think the relevant part of that code is:
You want to turn that around:
Updated fiddle
Or if you want to replace the previous link title with the new one, use
htmlortextrather thanappend:Updated fiddle