[ Web 관련 ]/jQuery
jquery data- 사용하기
BIZLAB
2023. 2. 27. 18:31
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
</head>
<body>
<div id="zero" hidden="false" name="zero" class="babo" value="Hello" data-air="23" alyt="77" >Content</div>
<script type="text/javascript">
$(document).ready(function() {
$('#zero').data('air'); // 23
alert($('#zero').attr('alyt'))
$('#zero').data('air', 24); // 24로 data-air를 24로 변경
document.getElementById('zero')['data-air'] = 24;
});
</script>
</body>
</html>