

On a procedural and computer level, it won’t cause any issues.

Unfortunately, though it’s a pretty easy technique, it’s also considered deprecated.

It’s an easy way to setup a user-controlled interface - users are used to clicking on links and the developer doesn’t have to scan for any specific action from the user. But you could also use the onHover action to process the JavaScript when the user just puts their cursor on the link, or a variety of other “on mouse move” actions.ĭevelopers often use “A” links in this way because it’s just very easy. When you call a JavaScript function through the HREF, it’s similar to onClick JavaScript - the script function processes when you click the link. In fact, you can create JavaScript code that launches within the HREF attribute of a URL: Click And then the closes the tag.īut the HREF attribute doesn’t have to include a URL. The HREF attribute is where the link goes. In the above, the tag is the beginning of the link. You know it as any link that generally shows up as blue and underlined: a connection to another page.Ī hyperlink, in HTML, is written as follows: Google Web Search A hyperlink is the basic foundation of the internet. In this case, though, we aren’t using buttons. Buttons are usually used in HTML forms, but other than form submission, they need JavaScript for more advanced functionality. In fact, an interesting element is that this button would essentially be a worthless element without using JavaScript to process some form of code. The JavaScript_Function() itself would be at the top of the page (“HEAD” section), but the button would be in the middle of the page (“BODY” section). The JavaScript that you wrote would be processed when the user “clicked” the button. But though the “HEAD” section stores the code, it’s usually called in the “BODY.” Calling JavaScript code means that you need to know “when” that code is going to be processed - usually based on a user action. Anything within the HTML tag is essentially the code of the website page. The “HEAD” area of an HTML page can store JavaScript code. Before we understand why we’d use the HREF attribute, we should understand how we use JavaScript in a website. Most people are familiar with HTML before they start programming in JavaScript, but not all. Here's a common debounce floating around the net, though do look for more advanced ones as featuerd in lodash.The most up-to-date JS resource online! Master Javascript by building a beautiful portfolio of projects! | By Colt Steele, Stephen Grider Explore Course Calling a JavaScript Function through HREF Window.addEventListener('resize',debounce(handler, delay, immediate),false) Use a debounce function to mitigate the excess calls. The resize event should never be used directly as it is fired continuously as we resize.
