Operating element attribute / tag attributes, methods, native, jq, h5

1. native operation js

dom.setAttribute ( 'attribute name', 'attribute')
dom.getAttribute ( 'attribute name')
div.setAttribute('id','ke')
console.log(div.getAttribute('name'))

dom.removeAttribute ( 'attribute name')

var box=document.getElementById('box')
box.removeAttribute('hehe')

2.jquery operation

$ .Attr ( 'attribute name', 'attribute')

$ .Attr ( 'attribute name')

$("td").attr('aa','hh')
$("td").attr('bb')

A plurality of attributes $ .attr ({property name: "attribute value", the attribute name: "attribute value"})

 
$ ( "img") attr ({. 
     title: "good note", 
     alt: "Farewell" 
   })
 

3.html5 operation

Custom property to begin with data-

Setting operation:. Dom.dataset attribute name = "attribute value"

Get operation:. Dom.dataset or attribute name dom.dataset

console.log(div.dataset)
console.log(div.dataset.id)

 

Guess you like

Origin www.cnblogs.com/yuanjili666/p/11853971.html