perkes456 perkes456 - 6 months ago 10
PHP Question

Accessing value of the div tag

I have a following HTML structure:

<div class="swiper-container2">
<div class="swiper-wrapper">

<div class="swiper-slide"><h3>January</h3></div>
<div class="swiper-slide"><h3>February</h3></div>
<div class="swiper-slide"><h3>March</h3></div>
<div class="swiper-slide"><h3>April</h3></div>
<div class="swiper-slide"><h3>May</h3></div>
<div class="swiper-slide"><h3>June</h3></div>
<div class="swiper-slide"><h3>July</h3></div>
<div class="swiper-slide"><h3>August</h3></div>
<div class="swiper-slide"><h3>September</h3></div>
<div class="swiper-slide"><h3>October</h3></div>
<div class="swiper-slide"><h3>November</h3></div>
<div class="swiper-slide"><h3>December</h3></div>

</div>
<!-- Add Pagination -->

<!-- Add Arrows -->
<div id="swiperNext" class="swiper-button-next"></div>
<div id="swiperPrevious" class="swiper-button-prev"></div>
</div>


The above is a list of months that I load into my slider, which acts as a swiper. And these are swiper buttons (which are basically div tags):

<div id="swiperNext" class="swiper-button-next"></div>
<div id="swiperPrevious" class="swiper-button-prev"></div>


And I've created on click events on them in jquery like following:

$('#swiperNext').click(function(e)
{
alert('Next button pressed');
});
$('#swiperPrevious').click(function(e)
{
alert('Previous button pressed');
});


Now I'm supposed to pick up the current value inside the slider (month name) and pass the value from the slider into the JS onclick function, which will then be passed into my my PHP funciton ... Can someone point me in the right direction ?

Thanks!

Answer

Found this in the docs: swiper-slide-active is the currently active element's classname, so:

$('.swiper-slide-active').html() is NOT working

but $('.swiper-slide-active h3').html() does work.

( http://idangero.us/swiper/api/#.V0f-6L52OPs )

Comments