jquery - How to change class name tag a with specific href? -


here problem.

<a class="selected" href="#tab-general">general setting</a> <a href="#tab-setting1">method 1</a> 

this time, it's auto selected #tab-general. after click button want auto select #tab-setting1. try thing didn't work:

var text='#tab-setting'+1; $('.selected').attr('class',''); $('a[href$=text]').attr('class', 'selected'); 

thanks help.

text variable. change

$('a[href$=text]').attr('class', 'selected'); //this selector not read value of variable `text` 

to

$('a[href$='+text+']').attr('class', 'selected'); 

i suggest similar below.

html:

<a class="link selected" href="#tab-general">general setting</a> <a class="link" href="#tab-setting1">method 1</a> 

jquery:

$('.link').on("click",function(){     $('.link').removeclass("selected");     $(this).addclass("selected"); }) 

fiddle


Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -