{"id":16364,"date":"2022-09-06T06:03:26","date_gmt":"2022-09-06T13:03:26","guid":{"rendered":"https:\/\/coderpad.io\/?p=16364"},"modified":"2023-06-05T14:11:59","modified_gmt":"2023-06-05T21:11:59","slug":"addeventlistener-javascript","status":"publish","type":"post","link":"https:\/\/coderpad.io\/blog\/development\/addeventlistener-javascript\/","title":{"rendered":"AddEventListener JavaScript: What It Is and How To Use It"},"content":{"rendered":"\n<p>JavaScript event listeners (or event handlers) are essential in web development. Why? Events constantly occur on your website, and they often change the interface.&nbsp;<\/p>\n\n\n\n<p>Event handlers provide a built-in solution for configuring activities anytime your page changes.&nbsp;<\/p>\n\n\n\n<p>In this post, you&#8217;ll learn about <code>addEventListener<\/code>, a particular event handler in JavaScript. We&#8217;ll cover its definition, syntax, and code example. In the end, you&#8217;ll learn how to remove the handler using <code>removeEventlistener<\/code>&nbsp;and some other concepts.<\/p>\n\n\n\n<p>Let&#8217;s get to it.&nbsp;<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>What is addEventListener in JavaScript?<\/strong><\/h2>\n\n\n\n<p>When a user or browser interacts with a webpage, an&nbsp;<em>event<\/em>&nbsp;occurs. Event handlers are used to create a customized piece of code that will run in response to specific events (e.g., opening a pop-up window when a user clicks a button). Some events are user-generated, while some are generated by APIs.&nbsp;<\/p>\n\n\n\n<p>JavaScript includes a built-in method called <code>addEventListener<strong>.<\/strong><\/code>&nbsp;It&#8217;s a&nbsp;<a href=\"https:\/\/en.wikipedia.org\/wiki\/DOM_events#DOM_Level_2\" target=\"_blank\" rel=\"noreferrer noopener\">DOM Level 2<\/a>&nbsp;event handler. You can use it to attach an event handler to a specific element. It in no way replaces the existing event handlers<em>.<\/em>&nbsp;<\/p>\n\n\n\n<p><code>addEventListener<\/code>&nbsp;makes adding many event handlers to one element easy &#8212; it lets you respond to events associated with an element via an event handler function. The <code>change<\/code>&nbsp;effect is an example of an event. You can attach an event handler to any DOM object.&nbsp;<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"719\" height=\"146\" src=\"https:\/\/d2h1bfu6zrdxog.cloudfront.net\/wp-content\/uploads\/2022\/09\/image.png\" alt=\"\" class=\"wp-image-16372\" srcset=\"https:\/\/coderpad.io\/wp-content\/uploads\/2022\/09\/image.png 719w, https:\/\/coderpad.io\/wp-content\/uploads\/2022\/09\/image-300x61.png 300w\" sizes=\"auto, (max-width: 719px) 100vw, 719px\" \/><\/figure>\n<\/div>\n\n\n<h2 class=\"wp-block-heading\"><strong>AddEventListener syntax in JavaScript<\/strong><\/h2>\n\n\n\n<p>Let&#8217;s take a look at the syntax: <code>target.addEventListener(event, function, useCapture)<\/code>&nbsp;<\/p>\n\n\n\n<p><code>addEventListener<\/code>&nbsp;has three parameters. <code>event<\/code>&nbsp;and <code>function<\/code>&nbsp;are most frequently used. <code>useCapture<\/code>&nbsp;is used occasionally.&nbsp;<\/p>\n\n\n\n<p>Here&#8217;s what all that syntax means:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>target<\/code>&nbsp;is the most important parameter; it specifies the DOM object you wish to attach an event listener to. HTML elements are frequently targeted DOM objects.<\/li>\n\n\n\n<li><code>event<\/code><strong>&nbsp;<\/strong>is a necessary parameter. It&#8217;s a string that provides the event&#8217;s name. The first thing to remember is that the parameter value does not include the prefix &#8220;on.&#8221; For instance, use &#8220;change&#8221; rather than &#8220;onchange.&#8221; Some DOM events are<code>click<\/code>, <code>change<\/code>, <code>drag<\/code>, <code>copy<\/code>, etc.<\/li>\n\n\n\n<li><code>function<\/code><strong> <\/strong>is a piece of code that triggers when the event fires. It makes the web pages dynamic and is an essential part of the method. Want to learn more about how JavaScript functions work under the hood? Read our guide<strong>&nbsp;<\/strong><a href=\"https:\/\/coderpad.io\/blog\/development\/what-you-never-learned-about-javascript-functions\/\" target=\"_blank\" rel=\"noreferrer noopener\">here<\/a>.<\/li>\n\n\n\n<li><code>useCapture<\/code>&nbsp;is an optional parameter. It&#8217;s a Boolean data type with either true or false values. <code>addEventListener<\/code>&nbsp;executes in two phases\u2014capturing or bubbling\u2014and <code>useCapture<\/code>&nbsp;sets the propagation phase.<\/li>\n<\/ul>\n\n\n\n<p>To better understand <code>useCapture<\/code>, let&#8217;s take a closer look at bubbling and capturing.&nbsp;<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>What are bubbling and capturing?<\/strong><\/h3>\n\n\n\n<p>We can better explain this by looking at a parent element and its child\u2014for example, a <code>div<\/code>&nbsp;and a <code>button<\/code>&nbsp;inside it.&nbsp;<\/p>\n\n\n\n<p>Suppose I applied a <code>click<\/code>&nbsp;event on both elements using <code>addEventListener<\/code>. Which element event gets handled first when a user clicks the button? Well, it depends on the propagation phase.&nbsp;<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Bubbling<\/strong>&nbsp;is an&nbsp;<em>inside-out&nbsp;<\/em>execution phase. That means that execution starts from the inner element and then will move to the&nbsp;<em>outermost<\/em>&nbsp;element&#8217;s event. Therefore, the <code>button<\/code>&#8216;s event will be handled first, followed by the <code>div<\/code>&nbsp;element&#8217;s event<em>.<\/em><\/li>\n\n\n\n<li><strong>Capturing<\/strong>&nbsp;is the opposite of bubbling<em>.&nbsp;<\/em>It starts the execution from the&nbsp;<em>outside<\/em><strong><em>.&nbsp;<\/em><\/strong>In this case, when you click the button, capturing makes the event listener handle the <code>div<\/code>&nbsp;element&#8217;s event first, then handles the&nbsp;<em>innermost&nbsp;<\/em>element&#8217;s event<em>.<\/em><\/li>\n<\/ul>\n\n\n\n<p>Do you want your event in a bubbling phase? Set the bubbling to <code>false<\/code>, which is the default value. Conversely, set the value to <code>true<\/code>&nbsp;to specify the capturing phase.&nbsp;<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>AddEventListener code example<\/strong><\/h2>\n\n\n\n<p>Now that you understand <code>addEventListener<\/code>&nbsp;and its syntax, let&#8217;s see it in action with a code example.&nbsp;<\/p>\n\n\n\n<p>Let&#8217;s say you want to give users the ability to hide paragraph text on a webpage by clicking a button. Here&#8217;s the initial HTML to build that:&nbsp;<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"HTML, XML\" data-shcb-language-slug=\"xml\"><span><code class=\"hljs language-xml shcb-wrap-lines\"><span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">html<\/span>&gt;<\/span>\n\t<span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">head<\/span>&gt;<\/span>\n\t\t<span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">meta<\/span> <span class=\"hljs-attr\">charset<\/span>=<span class=\"hljs-string\">\"UTF-8\"<\/span>&gt;<\/span>\n\t\t<span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">title<\/span>&gt;<\/span>addEventListener() Code Example<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">title<\/span>&gt;<\/span>\n\t\t<span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">link<\/span> <span class=\"hljs-attr\">rel<\/span>=<span class=\"hljs-string\">\"stylesheet\"<\/span> <span class=\"hljs-attr\">href<\/span>=<span class=\"hljs-string\">\"index.css\"<\/span>&gt;<\/span>\n\t\t<span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">script<\/span> <span class=\"hljs-attr\">src<\/span>=<span class=\"hljs-string\">\"index.js\"<\/span>\/&gt;<\/span><span class=\"handlebars\"><span class=\"xml\">\n\t<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">head<\/span>&gt;<\/span>\n\t<span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">body<\/span>&gt;<\/span>\n\t\t<span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">button<\/span> <span class=\"hljs-attr\">id<\/span>=<span class=\"hljs-string\">\"btn\"<\/span>&gt;<\/span>Click me<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">button<\/span>&gt;<\/span>\n\t\t<span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">p<\/span> <span class=\"hljs-attr\">id<\/span>=<span class=\"hljs-string\">\"myText\"<\/span>&gt;<\/span>Can you read me? Click the above button to hide me<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">p<\/span>&gt;<\/span>\n\t<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">body<\/span>&gt;<\/span>\n<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">html<\/span>&gt;<\/span><\/span><\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">HTML, XML<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">xml<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Now we need to access elements on the HTML file and assign a handler that listens for a <code>click<\/code> event. This handler will hide the paragraph when you click the button. Here&#8217;s the JavaScript to accomplish that:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript shcb-wrap-lines\"><span class=\"hljs-keyword\">let<\/span> myBtn=<span class=\"hljs-built_in\">document<\/span>.getElementById(<span class=\"hljs-string\">'btn'<\/span>);\n<span class=\"hljs-keyword\">let<\/span> msg=<span class=\"hljs-built_in\">document<\/span>.getElementById(<span class=\"hljs-string\">'myText'<\/span>);\n\nmyBtn.addEventListener(<span class=\"hljs-string\">'click'<\/span>, ()=&gt;{\n  msg.style.display=<span class=\"hljs-string\">'none'<\/span>;\n})\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Here&#8217;s what&#8217;s happening:<\/p>\n\n\n\n<p>You&#8217;ll see two elements in the HTML file, each with an ID. This enables them to be accessed by our JavaScript snippet.<\/p>\n\n\n\n<p>In the JavaScript file, you first create a variable <code>myBtn<\/code>. After that, you access the <code>button<\/code>&nbsp;element in the HTML with its ID. Eventually, you assign it to the variable you created.&nbsp;<\/p>\n\n\n\n<p>You then repeat the same action\u2013assign the <code>p<\/code><strong>&nbsp;<\/strong>element to a variable, then name the variable.&nbsp;<\/p>\n\n\n\n<p>Eventually, use <code>addEventListener<\/code>. Your target element is the button at this point, and the event is <code>click<\/code><em>.&nbsp;<\/em>Then, you create a function<em>.&nbsp;<\/em>This function adds <code>display: none<\/code><strong>&nbsp;<\/strong>to the <code>p<\/code>&nbsp;element<em>.<\/em>&nbsp;<code>useCapture<\/code>&nbsp;is <code>false<\/code>, the default value.&nbsp;<\/p>\n\n\n\n<p>To summarize, you can hide the paragraph by simply clicking on the button.&nbsp;<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>How to remove the handler<\/strong><\/h2>\n\n\n\n<p>To remove a handler, you&#8217;ll utilize JavaScript&#8217;s <code>removeEventListener<\/code>:<\/p>\n\n\n\n<p><code>target.removeEventListener(event, function, useCapture)<\/code> <\/p>\n\n\n\n<p><code>removeEventListener<\/code>&nbsp;has the same parameters as <code>addEventListener<\/code>, which makes it easy to implement when needed.&nbsp;<\/p>\n\n\n\n<p>To remove the event on the button element in the previous example, you can write the code as shown below:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-3\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript shcb-wrap-lines\"><span class=\"hljs-keyword\">let<\/span> myBtn=<span class=\"hljs-built_in\">document<\/span>.getElementById(<span class=\"hljs-string\">'btn'<\/span>);\n<span class=\"hljs-keyword\">let<\/span> msg=<span class=\"hljs-built_in\">document<\/span>.getElementById(<span class=\"hljs-string\">'myText'<\/span>);\n\nmyBtn.removeEventListener(<span class=\"hljs-string\">'click'<\/span>, ()=&gt;{\n  msg.style.display=<span class=\"hljs-string\">'none'<\/span>;\n})\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h2 class=\"wp-block-heading\"><strong>How to stop event propagation<\/strong><\/h2>\n\n\n\n<p>You may need to stop the propagation of an event because you only want it to affect a limited element.&nbsp;<\/p>\n\n\n\n<p>Let&#8217;s take a <code>div<\/code>&nbsp;and a <code>p<\/code>&nbsp;inside the div as a use case. You want to stop the event from getting to the <code>p<\/code> element.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-4\" data-shcb-language-name=\"HTML, XML\" data-shcb-language-slug=\"xml\"><span><code class=\"hljs language-xml shcb-wrap-lines\"><span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">div<\/span>&gt;<\/span>\n     <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">p<\/span>&gt;<\/span>I am a paragraph<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">p<\/span>&gt;<\/span>\n<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">div<\/span>&gt;<\/span>\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-4\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">HTML, XML<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">xml<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>The first thing to remember is that you can use <code>useCapture<\/code>&nbsp;to catch an event on the parent element before it gets to the children and stop it.&nbsp;<\/p>\n\n\n\n<p>To do this, you&#8217;ll need to set <code>useCapture<\/code><strong>&nbsp;<\/strong>to <code>true<\/code>&nbsp;and use the <code>stopPropagation<\/code>&nbsp;function on the event object, like so:&nbsp;<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-5\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript shcb-wrap-lines\">div.addEventListener(<span class=\"hljs-string\">\"click\"<\/span>, myFunc =&gt; {\n  <span class=\"hljs-built_in\">console<\/span>.log(<span class=\"hljs-string\">\"The child Event won't execute\"<\/span>)\n  myFunc.stopPropagation()\n}, { <span class=\"hljs-attr\">capture<\/span>: <span class=\"hljs-literal\">true<\/span> })\n\np.addEventListener(<span class=\"hljs-string\">\"click\"<\/span>, () =&gt; {\n  <span class=\"hljs-built_in\">console<\/span>.log(<span class=\"hljs-string\">\"You can't find me on the console\"<\/span>)\n})\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-5\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>When you run the code above, you&#8217;ll see <code>\"The child Event won't execute\"<\/code>&nbsp;logged to the console and nothing else. This happens because we stopped the event propagation on the parent using <code>stopPropagation<\/code>.&nbsp;<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Is it better to use addEventListener or onClick?<\/strong><\/h2>\n\n\n\n<p><code>onClick<\/code>&nbsp;is an example of an HTML event handler attribute. It&#8217;s also used to handle events. Meanwhile, <code>addEventListener<\/code>&nbsp;is the recommended way to assign event handlers.&nbsp;<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Why?<\/strong><\/h3>\n\n\n\n<p><code>addEventListener<\/code>&nbsp;gives you control over the execution phase. Bubbling and capturing are not easy to handle with <code>onClick<\/code><strong>.<\/strong>&nbsp;<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"726\" height=\"124\" src=\"https:\/\/d2h1bfu6zrdxog.cloudfront.net\/wp-content\/uploads\/2022\/09\/image-1.png\" alt=\"\" class=\"wp-image-16376\" srcset=\"https:\/\/coderpad.io\/wp-content\/uploads\/2022\/09\/image-1.png 726w, https:\/\/coderpad.io\/wp-content\/uploads\/2022\/09\/image-1-300x51.png 300w\" sizes=\"auto, (max-width: 726px) 100vw, 726px\" \/><\/figure>\n<\/div>\n\n\n<p>Additionally, <code>addEventListener<\/code>&nbsp;allows the addition of multiple events to an element. It also allows the addition of multiple handlers to an event. It works well with libraries and JavaScript modules.&nbsp;<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Before parting ways<\/strong><\/h2>\n\n\n\n<p><code>addEventListener<\/code>&nbsp;is an easy way to handle events on your websites. You can add multiple events to a particular element. You can remove events and even set the propagation phase. This is a superpower that enhances writing clean code.&nbsp;<\/p>\n\n\n\n<p>Play around with the code you learned today in the sandbox below:<\/p>\n\n\n<div\n\tclass=\"sandbox-embed responsive-embed  sandbox-embed--full-width\"\n\tstyle=\"padding-top: 85%\"\ndata-block-name=\"coderpad-sandbox-embed\">\n\t<iframe src=\"https:\/\/embed.coderpad.io\/sandbox?question_id=238392&#038;use_question_button\" width=\"640\" height=\"544\" loading=\"lazy\" aria-label=\"Try out the CoderPad sandbox\"><\/iframe>\n<\/div>\n\n\n\n<p><em>This post was written by Akande Olalekan Toheeb.&nbsp;<\/em><a target=\"_blank\" href=\"https:\/\/www.linkedin.com\/in\/akande-olalekan-toheeb-2a69a0221\/\" rel=\"noreferrer noopener\"><em>Akande<\/em><\/a><em>&nbsp;is a front-end developer and technical writer who loves teaching, learning, and building web tools and applications. He has experience with HTML, CSS, BOOTSTRAP, TAILWIND, LESS, SASS, GIT, NODEJS, and JAVASCRIPT and has built projects with other frameworks too.&nbsp;<\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Event listeners are essential in web development as they help in returning proper responses triggered by an event.<br \/>\nAddEventListener is a fundamental method in JavaScript &#8212; here&#8217;s everything you need to know about it.<\/p>\n","protected":false},"author":12,"featured_media":16380,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[9],"tags":[],"persona":[29],"blog-programming-language":[62],"keyword-cluster":[],"class_list":["post-16364","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-development"],"acf":[],"_links":{"self":[{"href":"https:\/\/coderpad.io\/wp-json\/wp\/v2\/posts\/16364","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/coderpad.io\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/coderpad.io\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/coderpad.io\/wp-json\/wp\/v2\/users\/12"}],"replies":[{"embeddable":true,"href":"https:\/\/coderpad.io\/wp-json\/wp\/v2\/comments?post=16364"}],"version-history":[{"count":82,"href":"https:\/\/coderpad.io\/wp-json\/wp\/v2\/posts\/16364\/revisions"}],"predecessor-version":[{"id":32677,"href":"https:\/\/coderpad.io\/wp-json\/wp\/v2\/posts\/16364\/revisions\/32677"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/coderpad.io\/wp-json\/wp\/v2\/media\/16380"}],"wp:attachment":[{"href":"https:\/\/coderpad.io\/wp-json\/wp\/v2\/media?parent=16364"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/coderpad.io\/wp-json\/wp\/v2\/categories?post=16364"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/coderpad.io\/wp-json\/wp\/v2\/tags?post=16364"},{"taxonomy":"persona","embeddable":true,"href":"https:\/\/coderpad.io\/wp-json\/wp\/v2\/persona?post=16364"},{"taxonomy":"blog-programming-language","embeddable":true,"href":"https:\/\/coderpad.io\/wp-json\/wp\/v2\/blog-programming-language?post=16364"},{"taxonomy":"keyword-cluster","embeddable":true,"href":"https:\/\/coderpad.io\/wp-json\/wp\/v2\/keyword-cluster?post=16364"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}