Joshua Joshua - 7 months ago 50
jQuery Question

Jquery indexOf on data-x

I search for a solution on my Jquery script. I need to create a indexOf on my data-x.

I have a string of several numbers, separated with a ','.

I have one number and i want to check if that number is equal with one of the numbers in the string.


I have tried with a if statement.

if(($(this).val().indexOf(answer_id) > -1)


<div class="enqueteitem enquetehidden" data-showfor="<?php echo $enquete['depend_answer_ids']; ?>">


You can use a contains selector. The * let you search for any existance of the answer_id in the attribute data-showfor

var elements = $('[data-showfor*="' + answer_id + '"]');