Use the .data()
method:
$('div').data('info', '222');
Note that this doesn’t create an actual data-info
attribute. If you need to create the attribute, use .attr()
:
$('div').attr('data-info', '222');
More Related Contents:
- Selecting element by data attribute with jQuery
- How to set data attributes in HTML elements
- jquery get HTML 5 Data Attributes with hyphens and Case Sensitivity
- jQuery find element by data attribute value
- jquery change section with scrolling and animation
- How can I get the data-id attribute?
- Click button copy to clipboard
- Change the image source on rollover using jQuery
- Get checkbox value in jQuery
- Show div on scrollDown after 800px
- How to remove close button on the jQuery UI dialog?
- jQuery on window resize
- Adding attribute in jQuery
- Hide/Show Column in a HTML Table
- Set selected option of select box
- Submit form with Enter key without submit button? [duplicate]
- ‘dragleave’ of parent element fires when dragging over children elements
- Convert a HTML table data into a JSON object in jQuery
- How to draw a line between draggable and droppable?
- How to fade loop background images?
- Why is z-index ignored with position:static?
- Access Multiple Elements of same ID in jQuery
- HTML5 validation before ajax submit
- JQuery .data() not working?
- jQuery html attribute not working in IE
- What’s faster for including scripts, using CDN (Google) or storing them locally in website’s root?
- JQuery search in static HTML page with highlighting of found word
- Disable select options based on value *through the HTML only!*
- Possible to have a floating horizontal scrollbar?
- Can jQuery selectors be used with DOM mutation observers?