<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" href="homeWork.css">
<script src="./homeWork.js"></script>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div class='container'>
<div class='mango'> first div mango</div>
<div type='red' class='m2ango'>div red m2ango</div>
<div type='green' class='magngo'>div green magngo</div>
<li class='mango'>li mango
</div>
<div class='mango'>second div mango</div>
<li type='green' class='mango'>li green mango
</div>
<div id="div1"></div>
<div id="div2"></div>
</body>
</html>
this is my HTML file and I want to get all of the attributes' values, class: container class: mango type: red class:m2ngo type: green class: magngo class: mango class:mango ......
CodePudding user response:
you can do like this:
targetString:string | any = '<div class="AAAAA>A</div>'
const rExp : RegExp = /<([^> ] )([^>]*)>/;
const matches = targetString.match(rExp)
console.log(matches[2]);