Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

jquery get data attribute value

/* html */
<a data-id="123">link</a>

/* js */
$(this).attr("data-id") // returns string "123"

$(this).data("id") // returns number 123 (jQuery >= 1.4.3 only)
Comment

set data attribute with a string jquery

alert($('#outer').html());   // alerts <div id="mydiv" data-myval="10"> </div>
var a = $('#mydiv').data('myval'); //getter
$('#mydiv').attr("data-myval","20"); //setter
alert($('#outer').html());   //alerts <div id="mydiv" data-myval="20"> </div>
Comment

jquery data attribute

/* html */
<a data-number="123">link</a>

/* js */
$(this).attr("data-number") // returns string "123"

$(this).data("number") // returns number 123 (jQuery >= 1.4.3 only)
Comment

find element with data attribute jquery

$("ul").find(`[data-slide='${current}']`)
Comment

jquery get data attribute

<a data-id="123">link</a>


var id = $(this).data("id"); // Will set id to 123
Comment

jquery get data attribute

$('input[type=radio][name=supplier_price]').change(function () {
            var $id                   = $(this).val(),
                $price                = $(this).data('price'),
                $intend_price         = $(this).data('intend-price'),
                $product__month_price = $('#product__month_price'),
                $product_price        = $('#product_price');

            console.log($price, $intend_price);

        });
Comment

How get current data attribute value in jQuery?

<div id="123" data-img-flag="1">
	<image src="abc.png">
</div>

<div id="432" data-img-flag="0">
	<image src="abc.png">
</div>
<script>
alert($(popImgId).data('img-flag')); // when we use data function to get the data attribute value wll get all time value loaded at the time of DOM loaded
alert($(popImgId).attr('data-img-flag')); // value will get lates. If we change/update value using jquery will get updated value 
</script>
Comment

jquery get element by data attribute

$("ul[data-slide='" + current +"']");
Comment

PREVIOUS NEXT
Code Example
Javascript :: react native different styles for ios and android 
Javascript :: jquery switch class 
Javascript :: javascript game loop 
Javascript :: discord.js set activity 
Javascript :: electronjs npm start in full screen 
Javascript :: clear localstorage on click jquery 
Javascript :: sql json_extract 
Javascript :: makes number negative javascript 
Javascript :: javascript remove all style values in div 
Javascript :: shadow in react native 
Javascript :: sort array based on another array 
Javascript :: get child of child javascript 
Javascript :: how to disable react in jsx scope eslint 
Javascript :: moment day in range 
Javascript :: how to always run validators mongoose 
Javascript :: how convert object to string and string to object in javascript 
Javascript :: how to import background image in inline css in react 
Javascript :: java password regex 
Javascript :: curl post json file 
Javascript :: disable formcontrol angular 
Javascript :: replace string using javascript 
Javascript :: roblox headshot image 
Javascript :: xhr request 
Javascript :: get id of first td jquery 
Javascript :: get child routes using parent in angular 
Javascript :: react native release apk command 
Javascript :: define array with custom index javascript 
Javascript :: usestate array delete 
Javascript :: multidimensional array push in jquery 
Javascript :: get id by this jquery 
ADD CONTENT
Topic
Content
Source link
Name
8+6 =