How to Use NPM goURL > Javascript > How to Use NPM goURL

goURL is a very small NPM package (developed by KingRayhan) that allows you to redirect any DOM element to a specific URL through a click event.

How to Install the Package

npm install gourl
// or
yarn add gourl

If you want, you can also add this functionality to your project through CDN.

<script src="" />

Include package to your project


Now if you want to go to a specific link through a click event, you simply need to attach the data-href attribute to the DOM element.

Some Examples

<button data-href="">click</button>

<button data-href="" data-target="_blank">click</button>

<a href="#" data-href="">facebook</a>

<input type="text" value="instagram" data-href="" data-target="_blank">

<br> <br>

<span data-href="" data-target="_blank">youtube</span>

Available attributes

data-hrefput your hyperlink here to go
data-targetput url target method. supported values _blank and _self (Default)
Also read:  A Brief Intro to Node.js Module System with Code Example
Category Javascript

Leave Your Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.