Domanda

I trying to get the id of my sections and append the id attribute to the clicked button.

so it will show:

<div class="navigate-left">PREVIEW ID NAME SECTION</div>

<div class="navigate-right">NEXT ID NAME SECTION</div>

Any help would be much appreciated.

http://jsfiddle.net/3fJqZ/67/

$('.navigate-left').click(function() {
 $(this).attr('id').appendTo($('.navigate-left'));
});

$('.navigate-right').click(function() {
    $(this).attr('id').appendTo($('.navigate-right'));
});
È stato utile?

Soluzione

By some looking, I found that the current section has the class present. So, you can get the current section's id by using the below code.

$('.navigate-left').click(function () {
     var currentSection = $('section.present');
     var prevId = currentSection.prev('section').attr('id');
     var nextId = currentSection.next('section').attr('id');

     $(this).text(prevId);
     $('.navigate-right').text(nextId);

 });

 $('.navigate-right').click(function () {
     var currentSection = $('section.present');
     var prevId = currentSection.prev('section').attr('id');
     var nextId = currentSection.next('section').attr('id');

     $('.navigate-left').text(prevId);
     $(this).text(nextId);
 });

EDIT: The below demo gives you the ids of the previous & next sections below the arrows

jsFiddle DEMO

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top