Reputation: 5612
What I need to do is take the text of header tags one by one when you press the key 'h'. This is my code,
var currentHeader;
currentHeader = $(":header").first();
$(window).on('keyup', function (e) {
if (e.which === 72){ //h = 72
alert(currentHeader.text());
currentHeader = currentHeader.next(":header");
}
});
Unfortunately this code not working as expected and no error message passing :'(
What I need is alert the next header tag text each time I press the 'h' key
Upvotes: 0
Views: 32
Reputation: 24965
var headers = $(":header");
var currentHeader = headers.first();
$(window).on('keyup', function (e) {
if (e.which === 72){ //h = 72
alert(currentHeader.text());
// go to the next indexed header on the page, after the current header
currentHeader = headers.eq( headers.index(currentHeader) + 1 );
}
});
Upvotes: 1