Attribute manipulation of jQuery tags

 1. Get properties

  • Both custom and built-in attributes can be obtained
  • If you don't have this attribute, you get an undefined
$('img').attr('src')

2. Set properties

1. Single setting

$('img').attr('src', '01.gif')
// 如果没有这个属性就添加这个属性
$('img').attr('aaa', '呵呵')

2. Batch setting

$('img').attr({
    src: '01.gif',
    aaa: '呵呵'
})

3. Remove attributes

1. Single removal

$('img').removeAttr('src', '01.gif')

2. Batch removal

$('img').removeAttr({
    src: '01.gif',
    aaa: '呵呵'
})

Guess you like

Origin blog.csdn.net/qq_52421092/article/details/131254141