javascript - jQuery on click toggle siblings -


i trying toggle arrows when click link, on click action working cannot make siblings toggle.

have idea missing.

thanks

html code :

<div class="box">     <span class="info-box-title" >             <i class="fa fa-thumbs-up"></i>             <a class="toggle" href="#yeswebsite">                  <b>website</b>: <?php echo $parsedjson1->website; ?>             </a>     </span>     <div class="arrow-up">&#9650;</div>     <div class="arrow-down">&#9660;</div>     <div id="yeswebsite" class="hidden">         <p>informatiile privind pagina ta cuprind si adresa de website. aceasta trimite vizitatorii direct pe siteul tau pentru afla mai multe informatii. </p>     </div> </div> 

jquery code is

$("span>a.toggle").click(function () {      console.log('it works');      $(this).siblings(".arrow-up, .arrow-down").toggle(); }); 

$(this).siblings(".arrow-up, .arrow-down") finds siblings of <a> , required elements siblings of <span>.

<span class="info-box-title">     <i class="fa fa-thumbs-up"></i> -------- $(this).siblings() <-+     <a class="toggle"></a>         --------- $(this)--------------' </span> <div class="arrow-up">&#9650;</div>   ---- required <div class="arrow-down">&#9660;</div> ---- required 

use .closest() find parent,

$(this).closest('span').siblings(".arrow-up, .arrow-down").toggle(); 

Comments

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -