Can href be an ID?

how to pass id in href in html
href=#'' id jquery
html anchor id
can href have an id
a href
html id
id href and class are attribute
add id to href jquery

I'm learning about JavaScript from an udemy tutorial and I try to make API calls. There is a website about recipes and I make API calls. And I have a misunderstanding because until now I knew that an href is a link, not a number.

This is a piece of code from index.html and the href is an id:

  <a class="results__link results__link--active" href="#23456">
    <figure class="results__fig">
         <img src="img/test-1.jpg" alt="Test">
    <div class="results__data">
         <h4 class="results__name">Pasta with Tomato ...</h4>
         <p class="results__author">The Pioneer Woman</p>

And this is a recipe list that I receive if I make an API call and I need to put the recipe_id which is a number in the href. And I don't understand how can I put a number in the href

Yes. If the href is a # flowed by an element id it is what is called an anchor link. It will get you to the element with the given id in the same page. You can read more about it here.

Creating links, The anchor tag has several attributes you can add: href — the resource the link points to (either an external file or an anchor ID). id — a unique  <a href="" target="_blank">Home</a> <!-- Link will open in a new window or tab --> Name and ID. Specifies the name or id of an anchor and used with another href link to tell the browser to go to that section. Name attribute is not supported in HTML5 and hence use of ID attribute is recommended.

You can use a number as a hyperlink, in this case anyway.

The # means it is referring to an element with that id on the page. To my knowledge it is only classes that you cannot use a number at the beginning without escaping it.

You are also able to leave the current page and go to an element on a different page. You can do this by tailing your #id on to the url string you are used to seeing.

If you give more background into the project we might be able to give less vague answers.

HTML Tags/Link Tags/links to a named anchor, What I want to do is not have separate jquery scripts for each url. Instead I would like to have on script that can process any of these urls. 1. Reply  Well organized and easy to understand Web building tutorials with lots of examples of how to use HTML, CSS, JavaScript, SQL, PHP, Python, Bootstrap, Java and XML.

Can a href be an ID?

In short, Yes.

href doesn't necessarily always mean an external link, it could link to an element on the current html page, which from the example you have provided i think this is the case.

If you map your recipe_id as a id to an element in your page, and you then say reference the recipe_id as a href when you click your href the page should scroll / navigate to the element with that id.

Can I Have Numerical ID's In My URL Or None At All?, Syntax of anchor names; Nested links are illegal; Anchors with the id attribute When a user activates this link in a user agent, the user agent will retrieve the  Identify the of the destination url by using id="pagetitleid1450" and then open the page There can be more than 1 links on the same original page. For example the next url on the page can be < a class="title pagetitle" id="pagetitleid1451" href="#" target="_blank" > take me article 1451</a>

Make Entire Div Clickable, You can create a link to a named anchor by using the name attribute (or the id attribute). When linking within the same document, the A element is set as follows​. The id attribute specifies a unique id for an HTML element (the value must be unique within the HTML document). The id value can be used by CSS and JavaScript to perform certain tasks for the element with the specific id value. In CSS, to select an element with a specific id, write a hash (#) character, followed by the id of the element:

HTML links · WebPlatform Docs, By prepending your href with # , you can target an HTML element with a specific id attribute. For example, <a href="#footer"> will navigate to the <div id="footer">  While you’ll rarely use these optional attributes, you will be using the ‘href” attribute of the link tag. The “href” attribute defines the target of the link -the address of the page you’re linking to.

How to use id in the a href tag to identify the destination url, Note: A link does not have to be text. It can be an image or any other HTML element. HTML Links - Syntax. Hyperlinks are defined with the HTML <a>  You can even create links to other websites that utilize Fragment IDs. Your using a relative path to reference the ID. To make it work cross site, use root relative paths like so <a href="/sub/different_wbpage.html#id">. When linking to third party documents with a Fragment ID.

  • You can use a number as a component of the url as either a folder, file or query parameter, so long as the server understands it.
  • Generally a href is a link to a page. But a hrefcan also be can idor the combination of both, so your browser automatically scrolls to the specific id