Reputation: 2178
Its been a long day and I've learnt much about js but my heads fuzzled on this one, ok so I need to get one of the array numbers (depending on the one the user clicks into the settings below. but i have no idea how, ive tried reading up on arrays but i cant get my head around it. :/
Sorry, I need to call a function every time I click on a different link and i need the functions to repond to each div seperatly.
var navLink = new Array();
navLink[0] ='#one' < this is the Id of an href link.
navLink[1] ='#two'
navLink[2] ='#three'
navLink[3] ='#four'
navLink[4] ='#five'
navLink[5] ='#six'
var navDiv = new Array();
navDiv[0] ='#content-one' < this is the Id of a content div.
navDiv[1] ='#content-two'
navDiv[2] ='#content-three'
navDiv[3] ='#content-four'
navDiv[4] ='#content-five'
navDiv[5] ='#content-six'
var settings = {
objSlideTrigger: navLink[x], // link button id
objSlidePanel: navDiv[x] // slide div class or id
}
I hope i have explained myself well enough... sorry if i havent.
I know this works but it only works for one...
var settings = {
objSlideTrigger: '#one', // link button id
objSlidePanel: '#content-one' // slide div class or id
}
Heres a js fiddle that shows the core element of what im trying to achieve. Howeve this is just a single link and content box, i want multiple links and content boxes. that all respond individually to being selected. jsfiddle.net/BeU3U/6/
Upvotes: -1
Views: 76
Reputation: 984
You can probably achieve this with an array of JSON elements.
var nav = [
{"navLink": "#one", "navDiv": "#content-one"},
{"navLink": "#two", "navDiv": "#content-two"},
{"navLink": "#three", "navDiv": "#content-three"},
{"navLink": "#four", "navDiv": "#content-four"},
{"navLink": "#five", "navDiv": "#content-five"},
{"navLink": "#six", "navDiv": "#content-six"}
];
var settings = function (rowIndex) {
objSlideTrigger: nav[rowIndex]["navLink"],
objSlidePanel: nav[rowIndex]["navDiv"]
};
Upvotes: 1
Reputation: 29
try this one below
var settings = function (rowIndex)
{
objSlideTrigger:navLink[rowIndex],
objSlidePanel:navDiv[rowIndex]
}
Upvotes: 0
Reputation: 77778
I think this could work for you. Just make sure that navLinks
is always the same length as navDivs
.
var navLinks = [
'#one',
'#two',
'#three',
'#four',
'#five',
'#six',
];
var navDivs = [
'#content-one',
'#content-two',
'#content-three',
'#content-four',
'#content-five',
'#content-six',
];
var settings = [];
for (var i=0; i<navLinks.length; i++) {
settings.push({
objSlideTrigger: navLinks[i],
objSlidePanel: navDivs[i],
});
};
console.log(settings);
Output
[
{objSlideTrigger: "#one", objSlidePanel: "#content-one"},
{objSlideTrigger: "#two", objSlidePanel: "#content-two"},
{objSlideTrigger: "#three", objSlidePanel: "#content-three"},
{objSlideTrigger: "#four", objSlidePanel: "#content-four"},
{objSlideTrigger: "#five", objSlidePanel: "#content-five"},
{objSlideTrigger: "#six", objSlidePanel: "#content-six"},
]
Upvotes: 2