I am having some very frustrating issues with some jQuery script. I am building a site for a non profit I work for. The site will display the latest news headlines for five categories on the front page. Each category has its own tab and when you roll over it the respective category is displayed while the others are hidden.
I have tested the page and script with mac versions of Safari and Firefox as well as the windows version of Safari with no issues - everything works as it should. When I try it with IE 7+ or Firefox on windows it does something quite odd: the tabs and content will display for the first and second categories but when you scroll over any of the other categories the content from the second tab displays.
I am at a loss.
Here is the code (commented):
// Front Page News Panel Switcher
$(document).ready(function() { // hides all of the news containers $(\"div#newsContainer\").hide();
// makes the first container visible $(\"div#newsContainer.generalNews\").show();
// sets the first containers tab to its active state $(\"div#newsPanels li a.generalNews\").addClass(\"active\");
// hover function to switch tab and content states $(\"#newsPanels li a\").hover(function() {
// set variable based on class of the tab being hovered over var tgt = $(this).attr(\"class\");
// hides all of the news containers $(\"div#newsContainer\").hide();
// shows content for the new tab $(\"div.\"+tgt).show();
// resets tabs $(\"div#newsPanels li a\").removeClass(\"active\");
// sets new tab to active $(this).addClass(\"active\"); }); });
Here is the code without comments for clarity:
$(document).ready(function() { $(\"div#newsContainer\").hide(); $(\"div#newsContainer.generalNews\").show(); $(\"div#newsPanels li a.generalNews\").addClass(\"active\");
$(\"#newsPanels li a\").hover(function() { var tgt = $(this).attr(\"class\"); $(\"div#newsContainer\").hide(); $(\"div.\"+tgt).show(); $(\"div#newsPanels li a\").removeClass(\"active\"); $(this).addClass(\"active\"); }); });
You didn't give enough information. We could use a link to the site, we could also use the code for the site so that we can test the code locally to figure out a sollution.
#newsItem p a { margin: 0px 10px 5px 10px; color: #5e9ff7; text-decoration: underline; }
</style>
</head>
<body>
<div id=\"newsPanels\"> <ul> <li><a class=\"generalNews\">News</a></li> <li><a class=\"ngNews\">NG</a></li> <li><a class=\"kstarNews\">K-Star</a></li> <li><a class=\"k1News\">K1</a></li> <li><a class=\"k2News\">K2</a></li> </ul> <div id=\"newsContainer\" class=\"generalNews\"> <div id=\"newsItem\"> <h4>Tuesday, September 8th, 2009</h4> <h5><a href=\"\">[General News] This is the Headline from some piece of news relevant to the category. Click through will take you to the story.</a></h5> </div> <div id=\"newsItem\"> <h4>Tuesday, September 8th, 2009</h4> <h5><a href=\"\">This is the Headline from some piece of news relevant to the category. Click through will take you to the story.</a></h5> </div> <div id=\"newsItem\"> <h4>Tuesday, September 8th, 2009</h4> <h5><a href=\"\">This is the Headline from some piece of news relevant to the category. Click through will take you to the story.</a></h5> </div> </div> <div id=\"newsContainer\" class=\"ngNews\"> <div id=\"newsItem\"> <h4>Tuesday, September 8th, 2009</h4> <h5><a href=\"\">[Nancy Greene News] This is the Headline from some piece of news relevant to the category. Click through will take you to the story.</a></h5> </div> <div id=\"newsItem\"> <h4>Tuesday, September 8th, 2009</h4> <h5><a href=\"\">This is the Headline from some piece of news relevant to the category. Click through will take you to the story.</a></h5> </div> <div id=\"newsItem\"> <h4>Tuesday, September 8th, 2009</h4> <h5><a href=\"\">This is the Headline from some piece of news relevant to the category. Click through will take you to the story.</a></h5> </div> </div> <div id=\"newsContainer\" class=\"kstarNews\"> <div id=\"newsItem\"> <h4>Tuesday, September 8th, 2009</h4> <h5><a href=\"\">[K-Star News] This is the Headline from some piece of news relevant to the category. Click through will take you to the story.</a></h5> </div> <div id=\"newsItem\"> <h4>Tuesday, September 8th, 2009</h4> <h5><a href=\"\">This is the Headline from some piece of news relevant to the category. Click through will take you to the story.</a></h5> </div> <div id=\"newsItem\"> <h4>Tuesday, September 8th, 2009</h4> <h5><a href=\"\">This is the Headline from some piece of news relevant to the category. Click through will take you to the story.</a></h5> </div> </div> <div id=\"newsContainer\" class=\"k1News\"> <div id=\"newsItem\"> <h4>Tuesday, September 8th, 2009</h4> <h5><a href=\"\">[K1 News] This is the Headline from some piece of news relevant to the category. Click through will take you to the story.</a></h5> </div> <div id=\"newsItem\"> <h4>Tuesday, September 8th, 2009</h4> <h5><a href=\"\">This is the Headline from some piece of news relevant to the category. Click through will take you to the story.</a></h5> </div> <div id=\"newsItem\"> <h4>Tuesday, September 8th, 2009</h4> <h5><a href=\"\">This is the Headline from some piece of news relevant to the category. Click through will take you to the story.</a></h5> </div> </div> <div id=\"newsContainer\" class=\"k2News\"> <div id=\"newsItem\"> <h4>Tuesday, September 8th, 2009</h4> <h5><a href=\"\">[K2 News] This is the Headline from some piece of news relevant to the category. Click through will take you to the story.</a></h5> </div> <div id=\"newsItem\"> <h4>Tuesday, September 8th, 2009</h4> <h5><a href=\"\">This is the Headline from some piece of news relevant to the category. Click through will take you to the story.</a></h5> </div> <div id=\"newsItem\"> <h4>Tuesday, September 8th, 2009</h4> <h5><a href=\"\">This is the Headline from some piece of news relevant to the category. Click through will take you to the story.</a></h5> </div> </div> </div>
well I am looking at your code and I am not seeing what problem you are having. When I scroll over the tabs, they all show the correct information. Here is the code I tested.
I added a link to jquery-1.3.2.min.js into the head section of the file. then I changed the dates on the second and thrird block of news so that I could see that they are changing. Everything looks correct.
<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"> <html xmlns=\"http://www.w3.org/1999/xhtml\">
#newsItem p a { margin: 0px 10px 5px 10px; color: #5e9ff7; text-decoration: underline; }
</style>
</head>
<body>
<div id=\"newsPanels\"> <ul> <li><a class=\"generalNews\">News</a></li> <li><a class=\"ngNews\">NG</a></li> <li><a class=\"kstarNews\">K-Star</a></li> <li><a class=\"k1News\">K1</a></li> <li><a class=\"k2News\">K2</a></li> </ul> <div id=\"newsContainer\" class=\"generalNews\"> <div id=\"newsItem\"> <h4>Tuesday, September 8th, 2009</h4> <h5><a href=\"\">[General News] This is the Headline from some piece of news relevant to the category. Click through will take you to the story.</a></h5> </div> <div id=\"newsItem\"> <h4>news 1</h4> <h5><a href=\"\">This is the Headline from some piece of news relevant to the category. Click through will take you to the story.</a></h5> </div> <div id=\"newsItem\"> <h4>news 2</h4> <h5><a href=\"\">This is the Headline from some piece of news relevant to the category. Click through will take you to the story.</a></h5> </div> </div> <div id=\"newsContainer\" class=\"ngNews\"> <div id=\"newsItem\"> <h4>Tuesday, September 8th, 2009</h4> <h5><a href=\"\">[Nancy Greene News] This is the Headline from some piece of news relevant to the category. Click through will take you to the story.</a></h5> </div> <div id=\"newsItem\"> <h4>ng news 1</h4> <h5><a href=\"\">This is the Headline from some piece of news relevant to the category. Click through will take you to the story.</a></h5> </div> <div id=\"newsItem\"> <h4>ng news 2</h4> <h5><a href=\"\">This is the Headline from some piece of news relevant to the category. Click through will take you to the story.</a></h5> </div> </div> <div id=\"newsContainer\" class=\"kstarNews\"> <div id=\"newsItem\"> <h4>Tuesday, September 8th, 2009</h4> <h5><a href=\"\">[K-Star News] This is the Headline from some piece of news relevant to the category. Click through will take you to the story.</a></h5> </div> <div id=\"newsItem\"> <h4>ks news 1</h4> <h5><a href=\"\">This is the Headline from some piece of news relevant to the category. Click through will take you to the story.</a></h5> </div> <div id=\"newsItem\"> <h4>ks news 2</h4> <h5><a href=\"\">This is the Headline from some piece of news relevant to the category. Click through will take you to the story.</a></h5> </div> </div> <div id=\"newsContainer\" class=\"k1News\"> <div id=\"newsItem\"> <h4>Tuesday, September 8th, 2009</h4> <h5><a href=\"\">[K1 News] This is the Headline from some piece of news relevant to the category. Click through will take you to the story.</a></h5> </div> <div id=\"newsItem\"> <h4>kl news 1</h4> <h5><a href=\"\">This is the Headline from some piece of news relevant to the category. Click through will take you to the story.</a></h5> </div> <div id=\"newsItem\"> <h4>kl news 2</h4> <h5><a href=\"\">This is the Headline from some piece of news relevant to the category. Click through will take you to the story.</a></h5> </div> </div> <div id=\"newsContainer\" class=\"k2News\"> <div id=\"newsItem\"> <h4>Tuesday, September 8th, 2009</h4> <h5><a href=\"\">[K2 News] This is the Headline from some piece of news relevant to the category. Click through will take you to the story.</a></h5> </div> <div id=\"newsItem\"> <h4>k2 news 1</h4> <h5><a href=\"\">This is the Headline from some piece of news relevant to the category. Click through will take you to the story.</a></h5> </div> <div id=\"newsItem\"> <h4>k2 news 2</h4> <h5><a href=\"\">This is the Headline from some piece of news relevant to the category. Click through will take you to the story.</a></h5> </div> </div> </div>
ON another note. I just noticed that you code is bad in one spot. You have id="newsitem" defined several times. You can't do that. You need to change that to class="newsitem" Maybe that's the cause of the problem you are having. Same thing with newsContainer
Ah, turned out to be my lazy coding! Changed the repeating id's to classes and everything seems to be working fine across Safari, FF and IE, both windows and mac. Funny how it almost always ends up being something simple.
Thanks for your help. It is always great to have another set of eyes spot the issues.
I am having some very frustrating issues with some jQuery script. I am building a site for a non profit I work for. The site will display the latest news headlines for five categories on the front page. Each category has its own tab and when you roll over it the respective category is displayed while the others are hidden.
I have tested the page and script with mac versions of Safari and Firefox as well as the windows version of Safari with no issues - everything works as it should. When I try it with IE 7+ or Firefox on windows it does something quite odd: the tabs and content will display for the first and second categories but when you scroll over any of the other categories the content from the second tab displays.
I am at a loss.
Here is the code (commented):
Here is the code without comments for clarity:
Here is the jQuery (updated since my last post):
And here is the HTML with basic styling:
http://dev.mtseymourskiclub.com
I added a link to jquery-1.3.2.min.js into the head section of the file. then I changed the dates on the second and thrird block of news so that I could see that they are changing. Everything looks correct.
Thanks for your help. It is always great to have another set of eyes spot the issues.
I guess I can get some sleep now. Cheers.