Please rate how useful you found this document: 
Average: 2.2 (5 votes)

Link Methods

The following methods are available in the jQuery and Backbone objects for link controls.

link.getHref()

The link.getHref() method returns the URL (address) of the hyperlink.

$("#linkId").getHref()

Example:

When the user enters a new value in the "productName" textbox, verify that the new product name is also found in the link with the ID "productLink".

$("#productName").setOnchange(function(newVal, oldVal) {
    var productUrl = encodeURIComponent(newVal);
    //search for product name in product link
    if ($("#productLink").getHref().search(productUrl) == -1)
        alert("Warning: Product name '" +productUrl+ "' is not found in product link.");
}

link.setHref()

The link.setHref() method sets the URL (address) in a hyperlink.

$("#linkId").setHref("url")

Example:

When the user enters a new value in the "productName" textbox, set the link to use the product name in a link with the ID "productLink".

$("#productName").setOnchange(function(newVal, oldVal) {
    var productUrl = encodeURIComponent(newVal);
    var url = "http://www.acme.com/product/" + productUrl;
    $("#productLink").setHref(url);
}