javascript - Selecting multiple data attributes using jquery click() function -


<script>  	jquery(document).ready(function ($){  		function togglechevron(e) {  			$(e.target)  				.prev('.panel-heading')  				.find("i")  				.toggleclass('fa-plus fa-minus');        		   			}  			  			$('#accordion').on('hidden.bs.collapse', togglechevron);  			$('#accordion').on('shown.bs.collapse', togglechevron);    		    		});    	  </script> 
<div class="col-md-8 hidden-xs">						  	<div id="carousel">  	  <a href="#"><img src="<?php echo images. '/home-1.jpg' ?>" id="item-1" /></a>  	  <a href="#"><img src="<?php echo images. '/home-2.jpg' ?>" id="item-2" /></a>  	  <a href="#"><img src="<?php echo images. '/home-3.jpg' ?>" id="item-3" /></a>	  		      	      				        	</div>		      </div>    <div class="col-md-4 rooms-description">	  	<div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true">  	  <div class="panel panel-default">  		<div class="panel-heading" role="tab" id="headingone">  		  <h4 class="panel-title">				        			<a role="button" data-toggle="collapse" data-parent="#accordion" data-item="item-1" href="#roomsone" aria-expanded="true" aria-controls="roomsone">  			  <?php printf( esc_html__('standard studio', 'la-vida-suite')); ?>  			</a>  			<i class="fa fa-minus pull-right"></i>  		  </h4>  		</div>  		<div id="roomsone" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingone">  		  <div class="panel-body">  			<p><?php printf( esc_html__('extremely spacious , comfortable couples', 'la-vida-suite')); ?></p>  			<p><?php printf( esc_html__('located on eighth floor,', 'la-vida-suite')); ?></p>  			<p><?php printf( esc_html__('king or twin bed', 'la-vida-suite')); ?></p>  			<p><?php printf( esc_html__('some rooms connected (by request)', 'la-vida-suite')); ?></p>  			<p><?php printf( esc_html__('room size 30 m²', 'la-vida-suite')); ?></p>  		  </div><!-- panel-body-->  		</div>  	  </div><!-- panel-default-->  	  <div class="panel panel-default">  		<div class="panel-heading" role="tab" id="headingtwo">  		  <h4 class="panel-title">  			<a class="collapsed" role="button" data-toggle="collapse" data-parent="#accordion" data-item="item-2" href="#roomstwo" aria-expanded="false" aria-controls="roomstwo">  			  <?php printf( esc_html__('executive studio', 'la-vida-suite')); ?>  			</a>  			<i class="fa fa-plus pull-right"></i>  		  </h4>  		</div>  		<div id="roomstwo" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingtwo">  		  <div class="panel-body">  			<p><?php printf( esc_html__('extremely spacious , comfortable couples', 'la-vida-suite')); ?></p>  			<p><?php printf( esc_html__('located on ninth floor,', 'la-vida-suite')); ?></p>  			<p><?php printf( esc_html__('king or twin bed', 'la-vida-suite')); ?></p>  			<p><?php printf( esc_html__('some rooms connected (by request)', 'la-vida-suite')); ?></p>  			<p><?php printf( esc_html__('room size 30 m²', 'la-vida-suite')); ?></p>    		  </div><!-- panel-body-->  		</div>  	  </div><!-- panel-default-->  	  <div class="panel panel-default">  		<div class="panel-heading" role="tab" id="headingthree">  		  <h4 class="panel-title">  			<a class="collapsed" role="button" data-toggle="collapse" data-parent="#accordion" data-item="item-3" href="#roomsthree" aria-expanded="false" aria-controls="roomsthree">  			  <?php printf( esc_html__('deluxe 1 bedroom', 'la-vida-suite')); ?>  			</a>  			<i class="fa fa-plus pull-right"></i>  		  </h4>  		</div>  		<div id="roomsthree" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingthree">  		  <div class="panel-body">  			<p><?php printf( esc_html__('for more 1 couple or family', 'la-vida-suite')); ?></p>  			<p><?php printf( esc_html__('located on lower floors', 'la-vida-suite')); ?></p>  			<p><?php printf( esc_html__('king or twin bed', 'la-vida-suite')); ?></p>							          			<p><?php printf( esc_html__('apartment size 55 m²', 'la-vida-suite')); ?></p>  		  </div>  		</div><!-- panel-body-->  	  </div><!-- panel-default-->	   	</div><!-- panel-group-->  </div><!--col-md-4-->

i have taken 2 columns: col-md-8 , col-md-4. in col-md-4, there accordion having data-items item-1, item-2 , item-3. in col-md-8, there 3 images in carousel. i want result this. if 1 panel of accordion active, should display, corresponding image in carousel. example, if data-item=2 active, carousel having image id="item-2" should come up. have included script have given toggle option of (+,-) in accordion. how should write code in script desired result? need help.

append common elements common class. e.g.

class="collapsed mycommonelement"

then can use

$(.mycommonelement")

class selector assign click elements class.

also note should adopt $(.mycommonelement").on("click", function(){..} pattern if can better

$("").click()

approach number of reasons..


Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -