javascript - why parent is not working in jquery? -


could please tell me why parent function not working ?

here code

https://jsbin.com/gefacenefi/edit?html,js,output

 $(function () {          $('.add').click(function () {             $('.item').parent('li.nn').css('color', 'red');         });      }); 

expected output text red

<li class="nn">bhiooo</li> 

please following:

$(function () {     $('.add').click(function () {       $('.item').parent().siblings('li.nn').css('color', 'red');     }); }); 

also not closing li element properly. structure should following:

<!doctype html> <html> <head>    <meta charset="utf-8">    <meta name="viewport" content="width=device-width">    <title>js bin</title>    <script src="https://code.jquery.com/jquery-2.1.4.js"></script> </head> <body>    <button class="add">filler</button>    <div>       <ul>          <li class="nn">bhiooo</li>          <li class="m">hello22             <ul class="item">                 <li class="abc">123</li>                 <li class="pp">12</li>                 <li class="abc">78</li>                 <li class="ac">13</li>                 </li>             </ul>          </li>       </ul>    </div> </body> </html> 

Comments

Popular posts from this blog

php - Permission denied. Laravel linux server -

google bigquery - Delta between query execution time and Java query call to finish -

python - Pandas two dataframes multiplication? -