Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why href for link and src for script

Tags:

html

Again while typing I read this question but that's a different one...and that too is not solved yet, as the person who's answer is marked as correct, says this in the end

I don't know direct answer to your question, but I'm pretty curious about tag, too. Finding answer would probably include some web archives digging.

So the question is quiet simple, why are we using src attribute for <script> tag but href for a <link> tag, now that confuses me many times when am including stylesheets and scripts...why it can't be same? any specific reason for this?

For example

<script href="#"></script>
<link href="#" />

Or

<script src="#"></script>
<link src="#" />
like image 509
Mr. Alien Avatar asked Dec 20 '12 04:12

Mr. Alien


People also ask

Why do we use href in JavaScript?

Definition and Usage. The href attribute specifies the URL of the page the link goes to. If the href attribute is not present, the <a> tag will not be a hyperlink. Tip: You can use href="#top" or href="#" to link to the top of the current page!

What is difference between href and src?

HREF - Hyperlink Reference | Often used in tags to reference another page or web link. SRC - Source | Often used in tags to give the web page the source of an image, video or file.

Why is CSS href and JavaScript src?

The href attribute specifies the location (URL) of a resource, that an anchor element points to, or the location of a linked resource, like a stylesheet. While the src attribute is used to embed a resource - usually URLs - into a document, think embedded images ( <img> ) and <script> tags.

What is link href in JavaScript?

The href property sets or returns the URL of a linked document.


1 Answers

A link points somewhere via a hypertext reference (hence href). This is why we use <a href too.

A script takes its source from elsewhere and is embedded into the current page, hence src. Compare <img src

EDIT: Of course, another equally valid answer would be "It just does!" :p

like image 163
Niet the Dark Absol Avatar answered Oct 09 '22 16:10

Niet the Dark Absol