jQuery, Select by attribute value, adding new attribute

后端 未结 3 1406
南旧
南旧 2021-01-22 14:10

I have an anchor in my HTML. it has a page attribute with a value. So everytime it is clicked I use the page attribute value in my js. Now I want to set a style attribute with a

3条回答
  •  情话喂你
    2021-01-22 14:38

    With HTML like:

    Link 1​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​

    you could do:

    $('a[page=1]').addClass('selected').attr('test', 'hi!');​
    

    (i.e. better to change display using a css class [e.g. 'selected'] than the style attribute - but the attr call there shows how to add an attribute).

提交回复
热议问题