custom-data-attribute

Selecting custom data attributes in JQuery

[亡魂溺海] 提交于 2020-01-02 01:48:10
问题 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

Accessing data attribute using jquery returns undefined?

荒凉一梦 提交于 2020-01-01 02:44:11
问题 Inside my view i have a button as follow: <button data-assigned-id="@IdUser" onclick="updateClick()" type="button" class="btn btn-sm btn-default"></button> My div <div id="partial_load_div"> </div> Script function updateClick() { var id = $(this).data('assigned-id'); $('#partial_load_div').show(); $('#partial_load_div').load('/Users/UpdatePartial?id=' + id); } The id is always shows as undefined, i checked and @IdUser has always value then in chrome dev i got the error GET http://localhost

Escaping/encoding single quotes in JSON encoded HTML5 data attributes

烈酒焚心 提交于 2019-12-28 02:45:21
问题 In PHP, I use json_encode() to echo arrays in HTML5 data attributes. As JSON requires - and json_encode() generates - values encapsulated by double quotes. I therefor wrap my data attributes with single quotes, like: <article data-tags='["html5","jquery","php","test's"]'> As you can see, the last tag (test's) contains a single quote, and using json_encode() with no options leads to parsing problems. So I use json_encode() with the JSON_HEX_APOS parameter, and parsing is fine, as my single

Escaping/encoding single quotes in JSON encoded HTML5 data attributes

江枫思渺然 提交于 2019-12-28 02:45:12
问题 In PHP, I use json_encode() to echo arrays in HTML5 data attributes. As JSON requires - and json_encode() generates - values encapsulated by double quotes. I therefor wrap my data attributes with single quotes, like: <article data-tags='["html5","jquery","php","test's"]'> As you can see, the last tag (test's) contains a single quote, and using json_encode() with no options leads to parsing problems. So I use json_encode() with the JSON_HEX_APOS parameter, and parsing is fine, as my single

SelectListItem with data-attributes

落爺英雄遲暮 提交于 2019-12-28 01:51:28
问题 Is there anyway to have a SelectList prepopulated on ViewModel with data-attributes ? I want to do @Html.DropdownListFor(m=> m.CityId, Model.Cities); so it generates code like : <select id="City" class="location_city_input" name="City"> <option data-geo-lat="-32.522779" data-geo-lng="-55.765835" data-geo-zoom="6" /> <option data-geo-lat="-34.883611" data-geo-lng="-56.181944" data-geo-zoom="13" data-geo-name="Montevideo" data-child=".state1" value="1">Montevideo</option> <option data-geo-lat="

Find specific anchor tag and replace data atribute on click [closed]

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-25 18:41:40
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 6 years ago . I have following page structure <div class="main"> <article class="article"> <!-- ... --> <div class="article-footer> <ul> <li><a href="#" class="article-play" data-play="3" data-src="http://..."></a></li> <li>..

How do I link a hyperlink to an HTML5 <li> image that uses data attribues

淺唱寂寞╮ 提交于 2019-12-25 17:04:28
问题 This is a responsive HTML5 gallery that I've been working on recently. I just want each image to link to a different page. <li> <div data-alt="img03" data-description="<h3>Project</h3>" data-max-width="1800" data-max-height="1350" > <div data-src="images/xxxlarge/1.jpg" data-min-width="1300"></div> </div> </li> I know that it should be as simple as adding a <a href="#"></a> but this isn't working. I am open to hear about other options. Thanks. 回答1: You can access the values in data-attributes

How do I link a hyperlink to an HTML5 <li> image that uses data attribues

旧城冷巷雨未停 提交于 2019-12-25 17:04:22
问题 This is a responsive HTML5 gallery that I've been working on recently. I just want each image to link to a different page. <li> <div data-alt="img03" data-description="<h3>Project</h3>" data-max-width="1800" data-max-height="1350" > <div data-src="images/xxxlarge/1.jpg" data-min-width="1300"></div> </div> </li> I know that it should be as simple as adding a <a href="#"></a> but this isn't working. I am open to hear about other options. Thanks. 回答1: You can access the values in data-attributes

Change data-attribute on click of HTML elements

徘徊边缘 提交于 2019-12-25 13:17:15
问题 I am trying to apply changes to the DOM when a <tr> is clicked. When clicked, it should add data-state=enabled and data-display=expanded to the clicked <tr> while applying data-state=disabled and data-display=collapsed to every other <tr> . So it should look like highlighting the clicked row while disabling the other rows. Then, when a row is highlighted, and a user clicks elsewhere, it should reset to default , i.e. data-state=enabled and data-display=collapsed for all <tr> 's Currently, I

What happens if I don't preface data attributes with “data-”?

核能气质少年 提交于 2019-12-24 03:16:22
问题 I frequently end up storing data in DOM elements and make heavy use of custom data attributes and JQuery. I know the HTML5 spec says data attributes should have the data- prefix, but as far as I can tell there's no harm in naming my attributes whatever I want. Problem? 回答1: The only problem is in validation. Non-standard element attributes are not valid HTML5. So, there is no harm in them, but the danger of operating outside of any spec is that it may not be supported in the future or by a