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>

4.4
5
RM. 100 points

                                    //javascript get html data attribute

4.4 (5 Votes)
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
js queryselectorall data attribute queryselectorall in javascript to get data attribute value how to select data attribute in javascript using queryselectorAll search using an attribute in html document.queryselectorall javascript querySelectorAll dataset value javascript querySelectorAll dataset queryselectorall input with data value document.querySelectorAll('[data-target]'); js queryselectorall attribute js queryselectorall data attr js queryselectorall data atrtr javascript queryselectorall with attribute javascript foreach queryselectorall with data attribute queryselectorall dataset javascript queryselectorall get attribute queryselectorall button witj data attribute queryselectorall get div attribute value js queryselectorall data attribute = true javascript queryselectorall data attribute queryselector data attribute include javascript queryselector by data attribute value js queryselectorall select attribute querySelector by data id javascript dataset queryselector queryselector with data attribute queryselector class with attribute how to display query selector datata using queryselctorall and data attribute queryselector data attribute mdn document queryselector js query selector data queryselector attribute value queryselectorall array queryselector for data attribute get elements by attributes javascript queryselector on data attribute typescript queryselectorall data attribute vs queryselector select all attribute data javascript queryselector dataset js get element by data attribute javascript get element by attribute data js select by data attribute queryselector by data attribute vanilla javascript data selector select dataset javascrpt query selector data different thatn query select data attribute js javascript queryselector array javascript select element by data-id js queryselector data attribute javascript select data attribute select data attribute javascript get element by data value javascript find element by data attribute javascript javascript selector data- get element by data attribute javascript
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source