首页 > 网页编程资源索引, Javascript > Change Class Attribute in Firefox and IE

Change Class Attribute in Firefox and IE

Firefox and IE act differently when change class attribute. I used below codes to do this:

<SCRIPT LANGUAGE=”JavaScript”>
function locateHome() {
curUrl=location.href;
homeUrl=”<?php bloginfo(‘url’)?>/”;
homeEnUrl=”<?php bloginfo(‘url’)?>/?lang=en”;
homeZhUrl=”<?php bloginfo(‘url’)?>/?lang=zh”;
if(navigator.userAgent.indexOf(“MSIE”)>0) {
if ((curUrl==homeUrl) || (curUrl==homeEnUrl) || (curUrl==homeZhUrl)){
homeClass=nav.getElementsByTagName(“li”)[0].getAttribute(‘className’);
homeClass=homeClass+” current_page_item”;
nav.getElementsByTagName(“li”)[0].setAttribute(‘className’,homeClass);
}
}else {
if ((curUrl==homeUrl) || (curUrl==homeEnUrl) || (curUrl==homeZhUrl)){
homeClass=document.getElementById(“nav”).getElementsByTagName(“li”)[0].getAttribute(“class”);
homeClass=homeClass+” current_page_item”; //alert(“2″+homeClass);
document.getElementById(“nav”).getElementsByTagName(“li”)[0].setAttribute(“class”,homeClass);
}
}
locateHome();
</SCRIPT>

  1. 还没有评论。
  1. No trackbacks yet.

发表评论

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / 更改 )

Twitter picture

You are commenting using your Twitter account. Log Out / 更改 )

Facebook photo

You are commenting using your Facebook account. Log Out / 更改 )

Connecting to %s

加关注

Get every new post delivered to your Inbox.