Answers for "js get html data"

5

html javascript find data attribute

//javascript get html data attribute
<button data-id="1" >Click</button>
<button data-id="2" >Click</button>
<button data-id="3" >Click</button>
const btns=document.querySelectorAll('button[data-id]');
[...btns].forEach(btn => console.log(btn.getAttribute('data-id')))
Posted by: Guest on July-25-2020
5

javascript get data attribute value

const article = document.querySelector('#electric-cars');
 
article.dataset.columns // "3"
article.dataset.indexNumber // "12314"
article.dataset.parent // "cars"
Posted by: Guest on April-15-2020
0

how to get data from html page using javascript

<p id="par">hi</p>
<!--put script in head tag-->
<script type="text/javascript">
	document.getElementById('par')//then whatever u want to do with it like window.location or something//
</script>
Posted by: Guest on June-23-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language