javascript - Accessing the upper parent node of the DOM -


here code have problem with:

<ul id="nav">   <li>     <label style="display: inline;">       <a class="dkblue strong">search</a>     </label>     <br>     <a id="productnav1" href="javascript:void(0)" class="blck-dkblue">       <span>products</span></a>     <div class="clear"></div>                <div id="productnav" class="menu" style="display: block;">     <!--  open new section -->       <div class="level_1">         <section>           <header>             <h5>1</h5>             <label><small><strong>select</strong></small><br>category</label>           </header>           <div class="clear"></div>           <div class="pull-left">             <ul class="sep nav-product">               <li class="group">                 <a class="cat-name" href="#" style="cursor: default;">ac-dc</a>                          <ul class="nav-product">                   <div>                     <ul class="sep nav-product">                       <li>                         <a href="#">board mount</a>                                  <ul class="nav-product">                           <!--  open new section -->                           <div class="level_2">                             <div class="level_3">                               <section>                                 <div class="1stdiv"></div>                                 <h3 class="blue">lorem ipsum</h3>                               </section>                             </div>                             <section>                               <header>                               <h5>2</h5>                                 <label>                                   <small>                                     <strong>select</strong>                                   </small>                                   <br>&nbsp;                                   <a href="#" class="blue" style="cursor: default;">ac-dc</a>&nbsp;                                   <a href="http://www.test.com/ac-dc/boardmount" class="blue">board mount</a>&nbsp;                                 </label>                               </header>                               <div class="clear"></div>                               <div>                                 <ul class="sep nav-product">                                   <li class="group">                                     <a href="#" style="cursor: default;">surf corrected</a>                                     <ul class="nav-product">                                       <div>                                         <ul class="sep nav-product">                                           <li class="group">                                             <a href="#" style="cursor: default;">universal input</a>                                             <ul class="nav-product">                                               <div>                                               <ul class="sep nav-product">                                                 <li>                                                   <a href="http://www.test.com/ac-dc/boardmount/via-pfm">via pfm</a>                                                 </li> 

i trying access parent node code not working

$("#nav").on("click", "a", function () {     if (!this.href.match('#$') && !this.href.match('javascript')) {        alert($(this).parents('.level_2').children('a.blue').text());     }        // .append() }); 

i'm trying access this

<a href="#" class="blue" style="cursor: default;">ac-dc</a>&nbsp;<a href="http://www.test.com/ac-dc/boardmount" class="blue">board mount</a> 

when user clicks on via pfm append result "products > ac-dc board mount > via pfm"

.children() grabs immediate children option filter them selector. meant use .find('a.blue'). same .parents(). use .closest('.level_2') instead. edit: wrong. parents traverse upwards past 1 level.

your code little hard read. solves problem, can't confirm myself.

$(this).closest('.level_2').find('a.blue').text() 

docs:
.parents()
.children()
.closest()
.find()


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -