0

I want to pass the value of the limit in Jquery at the touch of a button. I almost found a solution, but can not quite understand. How to set the value to "limit:" the default and change it by pressing the button.

HTML

<button id="pagelimit default">1</button>
<button id="pagelimit">2</button>
<button id="pagelimit">3</button>

</div>

JS

function displayVals() {
var pagelim = $( "#pagelimit" ).val();
};

$('#product-grid').mixItUp({
pagination: {
    limit: $pagelim // insert button value
}
});

Please help me solve this problem.

1
  • instead of initializing var pagelim inside displayVals give it a global scope. Commented Dec 19, 2014 at 10:16

1 Answer 1

1

ID of an element must be unique... It looks like you want to update the limit option with the clicked button's text so

<button class="pagelimit default">1</button>
<button class="pagelimit">2</button>
<button class="pagelimit">3</button>

then

//this method is not used in the below code as we don't know which button was clicked here... if you share how the `displayVals` method is called then we can try to make this work
function displayVals() {
    var pagelim = $("#pagelimit").val();
};

jQuery(function ($) {
    $('.pagelimit').click(function () {
        //update the limit option
        $('#product-grid').mixItUp('setOptions', {
            limit: +$(this).text()
        });
    });

    //initialize the plugin
    $('#product-grid').mixItUp({
        pagination: {
            limit: 1
        }
    });
})
Sign up to request clarification or add additional context in comments.

4 Comments

You need to have some element with ID "pagelimit" somewhere for this to work, maybe a hidden text field.
'displayVals' method from the example on the page link.
@RQEST is that how you have wrote it... like an event handler... can you share how you have used it
The fact that I do not know how to use it properly, because I almost do not know JS

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.