What is < onclick=" return false;" > in HTML?

➊ Why is it used?

❑ Events automatically lead to certain actions performed by the browser.

❒ In some cases, we may not want default action to be performed.

❑ "return false" triggers browser to prevent taking default action.
➋ Let's break it down

✛ onclick
It's an HTML attribute.
It's being used to set inline event handlers.

✛ =""
The code written inside "" should be valid JS code.

✛ return false
Returning false from an inline event handler
➌ Inline Event Handlers

❑ HTML Elements provide few attributes which are there to assign event handlers. E.g., "onclick"

❒ The value assigned to this attribute has to be valid JS code kept inside 2 double quotes (" and ")

Example:

⇥ <button onclick="performAction()">
➍ Cancelling Event Propagation

❑ Returning "false" from inline event handlers is a way to ask browser to prevent taking default action.

❒ Example:

Clicking on an <a> loads a new page or, reloads current page. We can stop

⇥ <a href="#" onclick="return false;">Bang!</a>
⚠️ Warning ⚠️

⬒ Setting event handlers using HTML onevent attributes is not recommended.

⬔ They inflate our HTML code and hard to test and debug.

⬓ Keeping JavaScript separate from HTML is a good practice.
➏ Let's summarise

⬔ Inline event handlers can be assigned using HTML onevent attributes. (Not a good practice)

⬕ Returning "false" from inline event handlers is a way to ask browser to prevent taking default action.
With this we come to the end of this 🧵 where we discussed about "inline event handlers and preventing default actions".

If you don't want to miss such tutorial threads on HTML, CSS and, JavaScript, follow {@swapnakpanda}

Till we meet again, stay safe and stay sanitised. 👋

• • •

Missing some Tweet in this thread? You can try to force a refresh
 

Keep Current with Swapna Kumar Panda ✨

Swapna Kumar Panda ✨ Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @swapnakpanda

Jan 16,
💙 10K+ Followers
📅 15-JAN

1K ⇨ First 3 months
10K ⇨ Next 3 months

Though I have been sharing the best possible learning contents, the kind of love and support I have received from you all is beyond my words.

You will receive even better contents, that's my promise

To never pollute my timeline, I rarely share any non-educational tweets.

Today I thought of sharing few single-liners that I wrote before but never able to post them.

Please read and share your views.
Just because a 12 yo doing Web Dev, don't mistaken it as a child's stuff.
Read 10 tweets
Jan 14,
What is <a href="javascript:void(0)" > in HTML?

➊ Why is it used?

❑ When we click on a link, if we do not want the default behaviour of the browser to load a new page or refresh the same page.

❒ Instead, the browser performs the JavaScript attached to that link.
➋ Let's break it down

✛ javascript:
This is referred to as a Pseudo URL

✛ void
This is a JavaScript Operator

(0)
This is a JavaScript Expression
Read 12 tweets
Jan 10,
While "2" - 2 = 0, why is "2" + 2 = "22"?

A JavaScript 🧵
➊ '+' operator is overloaded for Strings

❑ The binary '+' operator is generally a "Number Addition" operator.

❒ When one of the operand is string, '+' rather acts like a "String Concatenation" operator. The other operand if not string is converted to string first.
➋ '-' operator operates on numbers only

❑ The binary "-" operator is known as a "Number Subtraction" operator.

❒ If any of the operand is not number, that is first converted to a number before evaluating the expression.
Read 8 tweets
Jan 4,
Why <!DOCTYPE html>?

➊ History

✪ In the old days of the web, pages were written in two versions: One for Netscape Navigator, and one for Microsoft IE.

✪ When the web standards were made at W3C, browsers could not just start using them, as doing so would break most existing sites on the web.
✪ Browsers therefore introduced two modes to treat new standards compliant sites differently from old legacy sites.

✪ Modes are: Quirks Mode and Standards Mode.

✪ For HTML documents, browsers use a DOCTYPE in the beginning of the document to decide which mode to handle.
Read 9 tweets
Jan 3,
How do you write it in HTML?

⇥ <img>
⇥ <img />
⇥ <img></img>

Which one should you use?

➊ Element Structure in HTML

⮑ Start Tag
Example: <div>
⮑ Content
Anything that's put between start and end tag
⮑ End Tag
Example: </div>
➋ Self Closing Tags

⬔ If you put a "/" before closing of the start tag, it's called a "Self Closing Tag".

Example: <img />

⬕ For a self closing tag, there won't be any content and, end tag.

Example: <img />abc</img> ✘
Read 7 tweets
Jan 1,
Why to use <meta charset="utf-8"> in HTML?

➊ What is it?

Let's break down.

✛ meta: It's a HTML tag that contains metadata about a web page.

✛ charset: An HTML attribute that defines the character encoding for your browser to use when displaying the website content.

✛ utf-8: It's a specific character encoding.
➋ Why is character encoding important?

✪ Most websites these days has to display characters which are not traditional ASCII characters.

✪ When received such characters in HTML source, Browsers should be able to handle those to display properly.
Read 7 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Too expensive? Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal

Or Donate anonymously using crypto!

Ethereum

0xfe58350B80634f60Fa6Dc149a72b4DFbc17D341E copy

Bitcoin

3ATGMxNzCUFzxpMCHL5sWSt4DVtS8UqXpi copy

Thank you for your support!

Follow Us on Twitter!

:(