custom-data-attribute

dataset vs .data - Difference?

我怕爱的太早我们不能终老 提交于 2019-12-02 20:12:07
I am reading some values in data attribute fields. I have seen two easy ways to read the data as shown below: var webappData = document.getElementById('web-app-data'), rating = webappData.dataset.rating; OR var effectData = $('.effects-list li'), creative = effectData.filter('[data-creative]').data("creative"); My question is which of these has better performance or do they really differ? I have a page with many data attributes that I am accessing and I would like to use the method that has the best performance. Any guidance on understanding the difference between the two would be appreciated.

How to use a button's “data-” attribute to call a selected JavaScript function

房东的猫 提交于 2019-12-02 19:32:42
I'm trying to set some data on my buttons such that it can be accessed onclick . I'm having no problem using JSON in a button's data attribute where the key value is a string. However, I can't figure out how to set the values to be a function. What I'd like to happen upon clicking the button in this demo code is for the click event to call the function option1() which will alert the string "hello outside". The error I'm getting is this: Uncaught TypeError: Property 'option1' of object #<Object> is not a function HTML (JSFiddle is here: http://jsfiddle.net/NDaEh/32/ ): <button type='button'

access html 5 data attribute in php

狂风中的少年 提交于 2019-12-02 05:44:55
问题 I have a form which includes <input id="user-id" type="text" data-user-id="" name="message" placeholder="type and send..." class="form-control"> data-user-id HTML5 data attribute. When I submit the form, I want to use the value of data attribute in a php class. How to access this data attribute in php? 回答1: Your user ID should be in a separate hidden field, such as: <input type="hidden" name="user_id" value="123"> <input type="text" name="message" placeholder="type and send..." class="form

access html 5 data attribute in php

a 夏天 提交于 2019-12-02 03:43:20
I have a form which includes <input id="user-id" type="text" data-user-id="" name="message" placeholder="type and send..." class="form-control"> data-user-id HTML5 data attribute. When I submit the form, I want to use the value of data attribute in a php class. How to access this data attribute in php? Your user ID should be in a separate hidden field, such as: <input type="hidden" name="user_id" value="123"> <input type="text" name="message" placeholder="type and send..." class="form-control"> Your message input shouldn't have an id of user-id and shouldn't need data-user-id at all. Data

jQuery .data() does not update HTML5 data attributes

ぃ、小莉子 提交于 2019-12-01 18:40:51
I am trying to add a " data-bind " attribute to a div using jQuery as follows: var messageViewModel = { data: ko.observable({ message: response.message, sendDateFmted: response.sendDateFmted, messageId: response.messageId }) }; $("<div>",{ class:"messageToAndFromOtherMember" }).data("bind", "template: { name: 'message-template', data: data }").appendTo("#messagesToAndFromOtherMember"); ko.applyBindings(messageViewModel); " data-bind " is required by KnockoutJs. However all I get is this empty div: <div class="messageToAndFromOtherMember"></div> Notice there is no such attribute as data-bind

Universal CSS selector to match any and all HTML data-* attributes [duplicate]

穿精又带淫゛_ 提交于 2019-12-01 18:17:45
This question already has an answer here: CSS selector for attribute names based on a wildcard 3 answers Is it possible to match all nodes that have a data-* attribute using only CSS? Here are examples of attributes I would like to match: data-scope data-sessionlink data-visibility-tracking I could do *[data-scope] *[data-sessionlink] *[data-visibility-tracking] but I am looking for something more compact. Furthermore, I don't know all possible data-* attributes I might encounter in my application. It is currenly impossible to use wildcard masks to select elements by an attribute-name part.

Do HTML5 custom data attributes “work” in IE 6?

*爱你&永不变心* 提交于 2019-12-01 16:11:52
Custom data attributes: http://dev.w3.org/html5/spec/Overview.html#embedding-custom-non-visible-data When I say “work”, I mean, if I’ve got HTML like this: <div id="geoff" data-geoff="geoff de geoff"> will the following JavaScript: var geoff = document.getElementById('geoff'); alert(geoff.dataGeoff); produce, in IE 6, an alert with “geoff de geoff” in it? You can retrieve values of custom (or your own) attributes using getAttribute . Following your example with <div id="geoff" data-geoff="geoff de geoff"> I can get the value of data-geoff using var geoff = document.getElementById("geoff");

Do HTML5 custom data attributes “work” in IE 6?

半城伤御伤魂 提交于 2019-12-01 15:10:01
问题 Custom data attributes: http://dev.w3.org/html5/spec/Overview.html#embedding-custom-non-visible-data When I say “work”, I mean, if I’ve got HTML like this: <div id="geoff" data-geoff="geoff de geoff"> will the following JavaScript: var geoff = document.getElementById('geoff'); alert(geoff.dataGeoff); produce, in IE 6, an alert with “geoff de geoff” in it? 回答1: You can retrieve values of custom (or your own) attributes using getAttribute . Following your example with <div id="geoff" data-geoff

Is Google indexing HTML custom data attributes?

本秂侑毒 提交于 2019-12-01 06:18:13
I'm building an AJAX based portfolio module using pushState / hash bangs and as I'm ruling out browsers without JavaScript the only thing that concerns me is how limited the HTML custom data attributes are when it comes to SEO. For example, using the code below: <ul class="gallery" data-anchor="/photography/example/" data-title="Example"></ul> Will the data-title be indexed, i.e. will that text content be gathered by Google? Or would I need to include a header tag in or around the list as a descriptive complement? The data-title is meant to be used as a new window title once the user clicks on

Append select option with an HTML5 data attribute using jQuery

為{幸葍}努か 提交于 2019-12-01 05:01:38
问题 I'm trying to construct a set of options for a select element, using jQuery. It's working except for the data attribute that should be included, which seems to being ommitted. Here is my code: // cJ is JSON object. // #currency is my select element. function makeCurDropDown(cJ) { $.each(cJ, function (i) { $('#currency').append( $('<option></option>').val(i).data("sym", cJ[i][0]).html(cJ[i][1]) ); }); } 回答1: Actually the data is set, but since you are using data method instead of the attr