0

I have JSFIddle https://jsfiddle.net/rinku16/tfsrnj8y/21/, i done all thing correctly but don't know where is error. Please correct me. You can get all my code at JSFiddle.

I want to move the focus button to next and previous button (only 1,2,3.... NOT on Previous and Next Button) based on button click next/previous. Initialy it will be on 0 orange colored button when i click next it move to 1 colored button and same case for previous button.

JS Code.

$(document).ready(function() {

$('#nextValue').click(function() {

    var x = $('.nav-numbers .btn :focus').filter(function () { 
        return this
      });

      $('#'+x).css({"background-color": ""});
      $('#'+x).next().css({"background-color": "#e67e22", "color": "#ffffff"});

});

$('#PreValue').click(function() {

    var x = $('.nav-numbers .btn :focus').filter(function () { 
    return this
  });

  $('#'+x).css({"background-color": ""});
  $('#'+x).prev().css({"background-color": "#e67e22", "color": "#ffffff"});

});

  $('.nav button').click(function() {

  /* var start = $(this).text() */;

  $(this).css({"background-color": "#e67e22", "color": "#ffffff"});


});

$('.nav button')[0].click()


});

Thanks

1 Answer 1

1

The problem lies with this line of code.

    var x = $('.nav-numbers .btn :focus').filter(function () { 
        return this
    });

This basically returns an empty object. "Focus" state only gets triggered when an element (such as a form input) that has received focus. It is generally triggered when the user clicks or taps on an element or selects it with the keyboard's "tab" key. You can read more about it here (https://developer.mozilla.org/en-US/docs/Web/CSS/:focus).

I've provided you a simple sample here https://jsfiddle.net/gu81cbkm/.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.