0
Hi how could write this code way more clean . It's a chaos đ
I tried to use class to manipulate dom. But i dont like the way it is. I want it more clean and short maybe. https://code.sololearn.com/WmFzjjc1GIY1/?ref=app
8 Respostas
+ 5
the script should be in the 3rd tab(JS).
maybe jquery is an option.
+ 3
Zeinab
you're right, there are shorter ways.
What you did was technically correct, but it's the hard way to go about it.
You don't have to define a class just to modify the DOM element.
to get the same result, you could have just used
<script>
const mylist=document.getElementById("list");
mylist.children[0].textContent = "index 1";
mylist.children[1].textContent = "index 2";
</script>
+ 1
Bob_Li no i meant to practice the use of class in manipulating dom.
I was wondering if my way of using class has a cleaner way
+ 1
1) separate javascript from html simply use window.onload = ()=>{
//your code goes here ......
} inside the javascript tab , the rest is okay to me .
2) practice however you want, happy coding :)
+ 1
Zeinab
using class is basically what frameworks like React and others work. It's just you're doing it from scratch. It will be a lot of work to recreate the functionalities, though.
perhaps you could try exploring web components?
+ 1
Bob_Li yeah i'm learning React
0
Oma Falk i did'n get your mean
0
Madrine Nansiimbi thanks sisđđœ