$(function(){
$('.tab2').live('click', function() {
$('#coverTextH3').text(data[1].H3)
$('#coverTextP').text(data[1].P)
});
});
Lets say I have a link <a href="www.link.com"></a> How do I pass data, the index of an array, to a jQuery function so I do not have to repeat my code, for each index [0]-[7]?
var data = [
{
H3: 'name',
p: 'more'
},
{
H3: 'string',
p: 'more strings'
}]
There are numerous options. If attaching handlers via javascript, I would select basing on element’s id or some custom attribute, not the class. So say you have a number of links like this:
javascript in this case would be
Alternatively, you can attach click handlers right in your
aelements declaration:and define
setCoverfunction like this:Each of alternatives require changes in your htlm. If for some reason it is not possible, you need to at least now the range of your tabs, which can be quite tricky.