custom-data-attribute

Can I use HTML5 data-* attributes as boolean attributes? [duplicate]

心已入冬 提交于 2019-12-05 12:46:20
问题 This question already has answers here : Are empty HTML5 data attributes valid? (4 answers) Closed 5 years ago . I want to use a custom boolean attribute to mark an element's contents as editable. I'm aware of the data-* attributes, but wasn't sure if they require a value. I don't need data-is_editable="false" , as the lack of the attribute would be equivalent. I only care if it's "true" (if the attribute exists). I know I can use other attributes like class but I don't want to as it seems

jQuery - How to add HTML 5 data attributes into the DOM

柔情痞子 提交于 2019-12-05 12:39:08
问题 I am trying to add a HTML 5 data attribute into the DOM. I have seen on the jQuery site the format for data attributes is: $('.pane-field-related-pages ul').data("role") === "listview"; But this doesnt seem to add anything into the DOM? How can I add the above data-role into the related ul tag? 回答1: Read this article From article jQuery.com - "The .data() method allows us to attach data of any type to DOM elements in a way that is safe from circular references and therefore from memory leaks.

Passing data to Bootstrap Modal without JavaScript

主宰稳场 提交于 2019-12-05 05:32:53
问题 I have a grid with image links on my page. When clicking one of them a modal should pop up with the image but in big format. Now I'm trying to achieve this without the use of javascript/jquery but just with data-attributes. At the moment I have this code: <!-- Generating the image link with PHP (laravel) --> <a data-toggle="modal" href="#myModal"> {{ HTML::image("img/$photo->Link", "$photo->Title", array("class"=>"thumbnail col-md-3")) }} </a> <!--The modal --> <section class="row"> <div

Selecting custom data attributes in JQuery

陌路散爱 提交于 2019-12-05 02:27:00
I have a list here <ul id="demo2" data-name="demo2"> <li data-value="here">here</li> <li data-value="are">are</li> <li data-value="some...">some</li> <!-- notice that this tag is setting a different value :) --> <li data-value="initial">initial</li> <li data-value="tags">tags</li> </ul> Where each li item has a custom data attribute. On JQuery how would get all of the values of each li element which has an attribute of data-value? I want to get their value. but this code of mine doesn't seem to be working $('#view-tags').click(function(){ $('li[data-value]').each(function(){ alert($(this).data

Can we specify custom data attribute values in CSS?

两盒软妹~` 提交于 2019-12-05 01:19:45
On elements I can specify the data attributes as, e.g. <div data-widget-type="MyWidgetType1" data-property1="20" data-property2="test"> ... </div> I want to capture these in a class e.g. .MyClass1 { data-widget-type:"MyWidgetType1"; data-property1:"20"; data-property2:"test"; } <div class="MyClass1"> ... </div> Is there a way to specify data attribute values in CSS? CSS is not HTML. You cannot set or change the value of an HTML attribute using CSS. Besides, why would you do this? HTML and CSS exist because of separation of concerns. HTML is for content and CSS is for presentation. Specifying

Do html5 data attributes need a value? [duplicate]

限于喜欢 提交于 2019-12-04 17:35:35
问题 This question already has answers here : Are empty HTML5 data attributes valid? (4 answers) Closed 4 years ago . I am wondering if html data attributes actually need a value to be applied? I wonder this because often all we want to know is if the attribute is actually set to act as a flag. (sure we could use a class for this; but realistically unless you are going to style these items differently then the flags are more data than a semantic item). A perfect example of this is if we want a

Hidden inputs vs HTML5 data attributes

给你一囗甜甜゛ 提交于 2019-12-04 15:30:58
问题 Something that's been bugging me recently is the use of HTML5 data attributes and when is the appropriate to use them. Typically, on a page that performs a number of AJAX calls to my server, I require the ID that is representative of the page being viewed. I've currently been storing this in a hidden <input> element on the page, which is then accessed and stored in a JS variable at the top of my jQuery doc ready call. I've been considering moving it to a data-id attribute on the body element,

Access object value from parameter attribute in C#

你说的曾经没有我的故事 提交于 2019-12-04 07:33:31
This is my method public Component SaveComponent([ValidateMetaFields] Component componentToSave) { ... } This is my custom attribute: [AttributeUsage(AttributeTargets.Parameter)] public class ValidateMetaFieldsAttribute : Attribute { public ValidateMetaFieldsAttribute() { // how to access `componentToSave` here? } } I am wondering is there a way to access componentToSave object from ValidateMetaFieldsAttribute ? I could not find any sample code or examples. No, attribute instances don't have any notion of the target they're applied to. Note that normally you fetch attributes from a target, so

jQuery 1.4.4: How to find an element based on its data-attribute value?

不羁岁月 提交于 2019-12-04 06:51:40
I imagine this should be a pretty trivial task but using Firefox for Mac, 3.6.12 the following does not work: // assign data attributes $('.gallery li').each(function(i) { $(this).data('slide',i+1); }); // outputting an empty jQuery object console.log($('.gallery li[data-slide]')); // this does not work either outputting an empty jQuery object console.log($("[data-slide]")); using Firebug I can see that all the data-slide attributes including their numerical value are correctly attached to the li s and logging out: $('.gallery li').each(function(index) { console.log($(this).data()); });

jQuery .data() does not update HTML5 data attributes

霸气de小男生 提交于 2019-12-04 04:17:04
问题 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