can we make the jquery syntax easier?

In Javascript, things wrapped in quotation marks are known as strings. A string is a series of letters, typically like a word, a sentence, etc. It’s a common way of communicating through code and in real life.

jQuery is using a magical function of its own design represented by $. Functions have arguments, which is basically asking for something. In real life, you’d say “I want… a soda.” So in code that would be something like
i_want("soda"). You have to wrap it in quotation marks because it’s a string.

So in jQuery, the reason you can’t shortcut that is because you’re telling jQuery what you want to access.

p represents a paragraph tag on the document.

.class represents an element containing the tag “class”

#id represents an element with the ID “id”

So when I write $("p"), that’s like saying I want... p and then you do something with it. Like $("p").fadeOut() will fade out all paragraph elements.

It’s just the way code, and communication, works in general.

Browse More Popular Posts

Leave a Comment