Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

how to select data attribute in javascript using queryselectorAll

    <!DOCTYPE html>
    <html>
        <head></head>
        <body>
            <p data-foo="0"></p>
            <h6 data-foo="1"></h6>
            <script>
                var a = document.querySelectorAll('[data-foo]');

                for (var i in a) if (a.hasOwnProperty(i)) {
                    alert(a[i].getAttribute('data-foo'));
                }
            </script>
        </body>
    </html>
Comment

queryselectorall data attribute

document.querySelectorAll("[data-foo='1']")
Comment

queryselectorall in javascript to get data attribute value

//javascript get html data attribute
Comment

queryselectorall data attribute

document.querySelectorAll("[data-foo]")
Comment

PREVIOUS NEXT
Code Example
Javascript :: moment from seconds 
Javascript :: To split a full name into first and last names in JavaScript 
Javascript :: check scroll top height in react js 
Javascript :: axios send post data 
Javascript :: button in vanilla js 
Javascript :: javascript cookie expire in 5 minutes 
Javascript :: tocapitalize javascript 
Javascript :: ckeditor get value 
Javascript :: javascript include js file 
Javascript :: Cast to ObjectId failed for value 
Javascript :: how to set html label value in jquery 
Javascript :: btn.addeventlistener 
Javascript :: how to convert json result into datatable c# 
Javascript :: gulp synchronous tasks 
Javascript :: js generate random color 
Javascript :: getting data from form node 
Javascript :: jquery event keycode 
Javascript :: nuxt looks for npm_modules on express 
Javascript :: hasownproperty 
Javascript :: nested loops js 
Javascript :: .sort javascript 
Javascript :: a function that calls itself js 
Javascript :: javascript difference between two dates in days 
Javascript :: get year from date javascript 
Javascript :: first and last char vowel reg exp same char 
Javascript :: part of sting js 
Javascript :: js trigger window resize 
Javascript :: using iframe in chrome console 
Javascript :: jquery set form target 
Javascript :: palindrome rearranging javascript 
ADD CONTENT
Topic
Content
Source link
Name
8+7 =