Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis+ 1
how to use arguements / return with strings.
function element(elm){ return document.querySelector("." + elm + "") } element("title").innerHTML = "red" element(".hasClass") element("#hasId").style.color = "red" That way I don't have to do the following: document.querySelector("title").innerHTML = "blue" document.querySelector(".hasClass").style.color = "yellow" .... Just trying to make things simpler. But, I'm not sure how i would get away with "string" and the variable in the element() function.
6 Respostas
+ 2
Ginfio can you post the code in the codeplay ground for the better understanding?
+ 2
She used post Es5, that is es6 and beyond syntax, here's what she meant in Es5 :
function $(elm) {
document.querySelector(elm) ;
}
+ 1
O, wait I think I got it.
function element(elm){
return document.querySelector(elm.toString())
}
I'd still like to see your ideas.
if you guys have something different.
+ 1
Mirielle maybe āget awayā is not the right word.
Okay... so..
what i meant is..
func(elm){
.......selector(elm);
}
Now how can i make elm into string, because if itās just (elm), itās gonna think itās a variable, and it wonāt work.
ā
but, i think i figured it out using toSteing()
+ 1
Mirielle without jQuery
with pure JS.