전체 페이지뷰

2013년 11월 19일 화요일

jquery ui tip

<nav>
     <ul>
       <li><a href="home" class="home">Home</a></li>
       <li><a href="blog" class="blog">Blog</a></li>
       <li><a href="catalog" class="catalog">Catalog</a></li>
       <li><a href="authors" class="authors">Authors</a></li>
       <li><a href="store" class="store">Store</a></li>
     </ul>
   </nav>

remove all parent class then
addClass then toggleClass at selected li tag :
$("nav ul li a").click(function(){
     $(this).parent().siblings().removeClass("selected");
     $(this).parent().attr('class', 'selected');
     $(this).parent().toggleClass('selected');
});

contain all a tag href in array :
var selectedArr = new Array();

$('nav ul li a').each(function(e) {
     e.preventDefault();
     selectedArr.push($(this).attr("href"));
});

duplicate value remove
selectedArr = selectedArr.filter( function(a){if (!this[a]) {this[a] = 1; return a;}},{});

/**
 * preventDefault() not working in the IE browser
 * @param e
 */
function prevDefault(e)
{
if (e.preventDefault)
{
e.preventDefault();
}
else
{
e.returnValue = false;
}
}

댓글 없음:

댓글 쓰기