jquery - Get the classname of closest element matching specific criteria and apply to another element -



jquery - Get the classname of closest element matching specific criteria and apply to another element -

ok, tricky one, , i'm in on head. can hack up, i'm trying avoid that.

here visual reference of i'm trying accomplish:

http://bit.ly/1vxum6i

if click on "user administration" link in left nav, you'll see content alter in center area, , tab name , icon alter downwards below. when click link, grabs class of link , applies tab, changes it's icon. works great. need work if click sub-link. example, if click "subscribers" in "user administration" category, should little people icon in tab. here's current script:

$(document).on( 'click', 'nav a', function( event ) { event.preventdefault(); $("nav a").removeclass("active"); $(this).addclass("active"); $('#nav-tabs .ui-tabs-panel:visible').load(this.href); $("#nav-tabs .ui-tabs-active a").text(this.text); $('#nav-tabs .ui-tabs-active a').attr('class', function(i, c){ homecoming c.replace(/(^|\s)ui-icon-\s+/g, ''); }); $("#nav-tabs .ui-tabs-active a").addclass(this.classname); $("#nav-tabs .ui-tabs-active a").attr("href",this.href); });

i know give every link in category classname of parent link, seems kind of unnecessary. i'm trying figure out how find closest "ui-icon-*" class , capture instead. i'm not smart plenty figure out logic, thought here might be.

you may want utilize closest jquery function: http://api.jquery.com/closest/

it traverse dom tree find first element match criteria. in case this.

$('nav a').click(function(e) { // homecoming <li class='category'>. var $category = $(this).closest('.category'); // link straight under category. var $categorylink = $category.find('> a'); var categoryclass = $categorylink.attr('class'); });

jquery closest

Comments

Popular posts from this blog

java Multi query from Mysql using netbeans -

c# - DotNetZip fails with "stream does not support seek operations" -

c++ - StartServiceCtrlDispatcher don't can access 1063 error -