The HTML language is constantly evolving. Or, at least, the W3C reserves the right to add new TAGS and ATTRIBUTES to the language.
How can we be sure that if we use an attribute
named trigger
(or any other word) that they won't create an attribute
called trigger
(or our word) with a different meaning
and break our code?
The answer is that the W3C promises to never add any attributes to the language that start with data-
.
So, as long as we use data-trigger
or data-
word, our code is safe.
Nothing prevents us from naming an attribute anything we want. We could call it trigger
But we run a very small risk if we don't name it data-something
It's easy enough to reduce the risk to zero.
If I have some HTML code, I can add attributes:
.attr()
method:
Buttons to submit forms have a default behavior.
I think it always works.
I don't understand this question. The jQuery .click()
method is used like
function masHandler(evt) { console.log(evt); evt.preventDefault(); alert(""MAS is very cool""); }what does console.log(evt) do?
console.log
is JavaScript's print
function. It prints its arguments to the JavaScript console in the browser.
Here, we are printing the event object, which the browser created and handed to our function as its argument.
Let's try it: second event handler
preventDefault()
is a method of an event object. So, it needs to be called on one of those.
Sure, we'll talk a lot about that today.
Let's contrast the following on the interactive ottergram
So, the .one()
gives us an error message.
Why would we want an error message? Because error messages make debugging easier, as opposed to code that just doesn't work for some unknown reason.