This came when I tried to figure how jQuery works. How can I declare a string and then convert it such that it becomes readable by machine. In short, how can I place the string without the quotes so that the string parses to document.querySelector
and then I add my brackets with the selector. Before, I had eval(S)(.wrapper).className = "red";
I basically want to achieve what is commented and here is the relevant code:
const S = "document.querySelector";
S(".wrapper").className = "red";
/* Below is how I want the final result as. */
/* document.querySelector(".wrapper").className = "red" */
html, body {
max-width: 100%;
overflow-x: hidden;
margin: 0;
padding: 0;
}
.wrapper{
width: 100%;
height: 100vh;
text-align: center;
top: 50;
left: 50;
color: dodgerblue;
}
.red {
color: red;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Dom.js</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="wrapper">
<h1>Dom.js</h1>
<p>Making Dom Manipulation Easier!</p>
</div>
<script src="app.js"></script>
</body>
</html>