So far I have used $ ('SELECTOR'); when selecting id, class or tag.
Every time you declare a selector, the computer checks the html source, and if so, it checks again and repeats this task.
But if you declare it as a variable, it is loaded only once when you first declare it and the information is stored in the variable.
Doing things as simple and short as you do today will hardly speed you up, but it can slow your site down when large sources are used.
Let's assume that we have a class called hello. Let's declare this hello class.
In the past, I declared something like the above and attached it to some function.
하지만 변수를 선언하면
var hello = $('.hello');
var is the command used to declare variables. hello is a name that you declare arbitrarily. And hello means $ ('.hello'); It means.
그럼 어떻게 활용할까요?
var hello = $('.hello'); hello.hide(); ex) If you use a variable without declaring it -> $('.hello').hide(); hello.show(); ex)If you use a variable without declaring it -> $('.hello').show();
In other words, it is equivalent to writing $ ('.hello') by creating a variable called hello.
So let's practice by example using variables.
Result of Example Using Variables
You can also display an alert window using jQuery. ^^
You can also use as above.
If you put usa_hi in parentheses in alert() ;, the value hi of usa_hi is output.
And in alert() if usa_hi is wrapped with ''
If you input as above, the phrase usa_hi will be printed instead of hi. If you wrap '', the phrase comes out. If there is no '', it is recognized as a variable.
var con1 = usa_hi + jp_hi;
This means that the value hi of usa_hi and the value konnnichiha of jp_hi are combined to enter the value of con1.
So the value of con1 would be hikonnnichiha? ^^
end.. Thank you ^^