html5-data

Are HTML 5 data- attribute and jQuery data same thing?

痞子三分冷 提交于 2019-12-12 04:44:18
问题 In HTML 5 its possible to set arbitrary 'data-' attributes to elements like <div data-blah="blah"> The jQuery framework has methods to do similar things ( .data() etc). My question is do the jQuery methods just manipulate and read these html5 data attributes, or they are referring to different jQuery-type data-attributes? 回答1: No, totally different things. jQuery's .data() existed even before HTML5. See: http://api.jquery.com/data/ for details. To get HTML5 data- attribute value from html tag

Having problems in IE8 when attempting to get data from target event

余生颓废 提交于 2019-12-11 10:01:51
问题 I have code such as this.. // Get some data var id = event.target.id; var flag_status = event.target.dataset.change; var winner_id = event.target.dataset.winner; var item_id = event.target.dataset.item; "Normal" browsers like Firefox and Chrome get the values with no problems and everything works great; however nothing is happening with IE8 so I'm assuming it can't get the data. The event parameter is passed to this function via this code: $('.shipping_status').click(function(event) { event

Assigning individual keys of object stored in jQuery.data()

一个人想着一个人 提交于 2019-12-11 05:04:10
问题 I have custom data stored on elements using jQuery.data() method. <div id="mydiv" data-test='{"1":"apple", "2":"banana"}'>Custom data</div> I know I can access individual keys of the object stored in data-test using $('#mydiv').data('test')["1"] But is it ok to re-assign individual keys like this ? It works but it isn't documented. Secondly, on inspecting the element using browser's developer tools, I still see the old value i.e. "apple" in this case. JSFiddle $('#mydiv').data('test')["1"] =

How to add HTML5 data- attributes to a rails form label tag?

青春壹個敷衍的年華 提交于 2019-12-10 12:35:59
问题 I have a rails form that has this code: <%= form_tag("../vehicles", method: "get") do %> <div> <div> <%= label_tag(:address, t("ui.reservations.pickup"), data-addr: 'here') %> </div> <div> <%= label_tag(:address, t("ui.reservations.between_now_and_param", param: @start_date.strftime( time_format))) %> </div> <div> I want to add a HTML data attribute to the first label, so I tried: <%= label_tag(:address, t("ui.reservations.pickup"), data-addr: 'here') %> but I get a syntax error: SyntaxError

using $.data(“value”) versus $.attr(“data-value”)

╄→гoц情女王★ 提交于 2019-12-07 14:41:11
问题 When I use jQuery.data to change the value the attribute in the DOM doesn't change. But I like when the attribute in the DOM changes, its much easier to debug stuff. So is it ok to use $().attr("data-value") to change data-attributes? Just a little fiddle to show that mixing $().attr and $().data won't work well together: http://jsfiddle.net/AvRJc/ 回答1: The data function manages a cache of data for an element that jQuery provides, not data-* attributes. The only interconnection between the

How to remove data-* attributes using HTML5 dataset

瘦欲@ 提交于 2019-12-05 08:28:15
问题 According to the dataset spec, how is element.dataset meant to delete data attributes? Consider: <p id="example" data-a="string a" data-b="string b"></p> If you do this: var elem = document.querySelector('#example'); elem.dataset.a = null; elem.dataset.b = undefined; elem.dataset.c = false; elem.dataset.d = 3; elem.dataset.e = [1, 2, 3]; elem.dataset.f = {prop: 'value'}; elem.dataset.g = JSON.stringify({prop: 'value'}); the DOM becomes this in Chrome and Firefox: <p id="example" data-a="null"

How to remove data-* attributes using HTML5 dataset

眉间皱痕 提交于 2019-12-03 23:27:23
According to the dataset spec , how is element.dataset meant to delete data attributes? Consider: <p id="example" data-a="string a" data-b="string b"></p> If you do this: var elem = document.querySelector('#example'); elem.dataset.a = null; elem.dataset.b = undefined; elem.dataset.c = false; elem.dataset.d = 3; elem.dataset.e = [1, 2, 3]; elem.dataset.f = {prop: 'value'}; elem.dataset.g = JSON.stringify({prop: 'value'}); the DOM becomes this in Chrome and Firefox: <p id="example" data-a="null" data-b="undefined" data-c="false" data-d="3" data-e="1,2,3" data.f="[object Object]" data.g="{"prop":

Using jQuery to get data attribute values with .each()

China☆狼群 提交于 2019-11-30 18:42:20
I have the following HTML with data attributes - I want to write some jQuery that will loop through the HTML and collect the data attributes and put them into an array - could anyone assist as I'm getting an error. ERROR in console log : item.data is not a function I am trying to use the data() attribute - can you see what I'm doing wrong? // My HTML code <span class="winners" data-userid="123" data-position="1" data-fullname="neil"> <span class="winners" data-userid="234" data-position="2" data-fullname="Ron"> <span class="winners" data-userid="421" data-position="3" data-fullname="Philip"> /

Using jQuery to get data attribute values with .each()

强颜欢笑 提交于 2019-11-30 02:06:50
问题 I have the following HTML with data attributes - I want to write some jQuery that will loop through the HTML and collect the data attributes and put them into an array - could anyone assist as I'm getting an error. ERROR in console log : item.data is not a function I am trying to use the data() attribute - can you see what I'm doing wrong? // My HTML code <span class="winners" data-userid="123" data-position="1" data-fullname="neil"> <span class="winners" data-userid="234" data-position="2"

How to do data- attributes with haml and rails?

泪湿孤枕 提交于 2019-11-29 16:04:42
问题 I can have %a{href: '#', data_toggle_description_length: 'toggle_me_ajax'} which it gives me underscores not dashes, i.e. <a href="#" data_toggle_description_length="toggle_me_ajax"></a> However I want to have HTML5 data- attributes, i.e. <a href="#" data-toggle-description-length="toggle_me_ajax"></a> but when I try replacing underscores with dashes, i.e. %a{href: '#', data-toggle-description-length: 'toggle_me_ajax'} I get syntax errors: /home/durrantm/Dropnot/webs/rails_apps/linker/app