I'm working on a simple JQuery function for a news page. Basically the idea is simple...I have a news text div and then I will add a variety of buttons for different news items. The idea is that when the user clicks on a button, the div loads with the proper news text in an array. Seems to only work on the last button, so something is wrong with my loop. I'm new to this so I'm a little stumped!
HTML CODE
<div id="textbtn0">Btn1</div>
<div id="textbtn1">Btn2</div>
<div id="textbtn2">Btn3</div>
<div id="textbox">This is text</div>
JQUERY CODE
jQuery(document).ready(function() {
var newsItems=new Array();
newsItems[0]="News1";
newsItems[1]="News2";
newsItems[2]="News3";
for(a=0;a<newsItems.length;a++){
var num=a;
jQuery("#textbtn"+num).mouseover(function() {
$("#textbtn"+num).css('cursor', 'pointer');
});
$("#textbtn"+num).click(function()
{
$("#textbox").html(newsItems[num]);
});
};
});