jquery get data attribute
/* html */
<a data-id="123">link</a>
/* js */
$(this).attr("data-id") // returns string "123"
$(this).data("id") // returns number 123 (jQuery >= 1.4.3 only)$("ul").find(`[data-slide='${current}']`)<a data-id="123">link</a>
var id = $(this).data("id"); // Will set id to 123$('.slide-link[data-slide="0"]').addClass('active');
data attribute in jquery
For setting attribute data to the element
Html
<p id="assign">Assigning data attribute</p>
jquery
$("#assign").data("title","firstparagraph");
Output:
<p id="assign" data-title="firstparagraph">Assigning data attribute</p>
For getting attribute data from the element
Html
<p id="assign" data-title="firstparagraph">Assigning data attribute</p>
jquery
console.log($("#assign").data("title"));
console.log($("#assign").data());
Output:
firstparagraph
{ title: firstparagraph }
Also in JavaScript:
- ERROR in ./node_modules/tns-core-modules/ui/core/view/view.js Module not found: Error: Can't resolve '@nativescript/core/ui/core/view/view' in '/home/deepali/projects/supersquad-client/node_modules/tns-core-modules/ui/core/view'
- js code to run hello world
- hoe lang is 50000 uur
- node js async delay
- javascript get sum array values
- create three js webgl renderer
- how to delete a line in vs code
- find char in string javascript
- append item to array javascript
- javascript square root
- how to get a String in dart
- appendchild element once if element present in js
- open close children modal react
- jquery dynamic event handling
- can the name of function be the same with name of variable js
- include multiple js files using jQuery $.getScript()
- using post from any button
- js object destructuring
- clear textinput react native
- can't bookmark react router
- javascript regex .test
- jquery get request with headers
- install swagger jsdoc
- Bots latency discord js