{"id":12259,"date":"2022-08-03T12:11:23","date_gmt":"2022-08-03T16:11:23","guid":{"rendered":"http:\/\/local.brightwhiz\/?post_type=snippets&p=12259"},"modified":"2022-08-03T12:11:26","modified_gmt":"2022-08-03T16:11:26","slug":"how-to-get-html-element-data-attribute-in-jquery","status":"publish","type":"snippets","link":"http:\/\/local.brightwhiz\/snippets\/how-to-get-html-element-data-attribute-in-jquery\/","title":{"rendered":"How to get HTML Element Data Attribute in jQuery"},"content":{"rendered":"\n
Take this data attribute as an example.<\/p>\n\n\n\n
<div id="element" class="element" data-name="Mary"><\/div><\/code><\/pre>\n\n\n\nGet the data attribute.<\/p>\n\n\n\n
\/\/get data-id using jQuery\nvar dataName = $('#element').data('data-name');\n\nconsole.log("dataName"); \/\/ Mary<\/code><\/pre>\n","protected":false},"comment_status":"open","ping_status":"closed","template":"","meta":[],"categories":[953,27,15,16],"tags":[303,328,333,350,424,471,638],"yoast_head":"\nHow to get HTML Element Data Attribute in jQuery Snippet<\/title>\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\t\n