5 < a class="Qlink" rel="21;6" ...">

Jquery find rel link

I have some links on my page

< a class="Qlink" rel="20;5" href="javascript:void(0);">5</a>
< a class="Qlink" rel="21;6" href="javascript:void(0);">6</a>
< a class="Qlink" rel="22;7" href="javascript:void(0);">7</a>

I make some ajax call and get the first number in the rel attribute (exp. 20)

how can I change the link class (first in my exp.)

+3
source share
3 answers
$("a[rel^='20;']").addClass('foo');

See also: attributeStartsWith

+18
source

The combination of Kobi and Soufiane answers will do what the OP asks:

$("a[rel^=20]").attr('class', 'your_new_class');

In the end, he asked me to change the class.

+3
source

If you want to change the class attribute of your links:

$('a.Qlink').attr('class','your_new_class');

Edit: Based on other answers, this is better:

$('a[rel^=20]').attr('class','your_new_class');
+1
source

Source: https://habr.com/ru/post/1723098/


All Articles