1

I want to check the classname with pattern eg. sort-order12, sort-order13 using the match function in jquery. The below usage is not working. Anyone can help ?

var sort_order = $('.js-data-selector.active:first').data('sort-order');

sort_order_next -> is the variable containing integer value.

var child = $("table tr td").filter(function() {
  return $(this).prop("class").match(/"sort-order"+(sort_order_next)/)
}).closest("tr");

child.show();

I am trying to display the nodes with classname with pattern "sort-order-1", "sort-order-2" etc. according to the node value (sort-order-next) obtained.

0

1 Answer 1

1

Try this

var sort_order_next = 12;

var child = $("table tr td").filter(function() {
  return $(this).prop("class").match(new RegExp('sort-order-' + sort_order_next));
}).closest("tr");

console.log(child);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table>
    <tr>
        <td class="sort-order-12"></td>
    </tr>
    <tr>
        <td class="sort-order-13"></td>
    </tr>
    <tr>
        <td class="some-cls"></td>
    </tr>
</table>

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

1 Comment

This code works.. !! Thanks for your help Alexander.. !

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.