jQuery .attr() method

0 votes
807 views
added Apr 2, 2018 in jQuery by LC Marshal Captain (25,790 points)

Find element and change the href value

$(".button a").attr("href", "http://www.hormart.com/");

6 Responses

0 votes
responded Apr 3, 2018 by LC Marshal Captain (25,790 points)
edited Oct 31, 2018 by LC Marshal

To change breadcrumb link no.3 to use PHP variable to replace the existing link

var lookfordistrict = $('ol.breadcrumb li:nth-child(3) a'); 
var districtlink = "/map-search-property?listing_type=<?php print $field_prop_listing_type; ?>&state=<?php print $field_state; ?>&district=<?php print $field_district; ?>";
$(lookfordistrict).attr('href', districtlink);
0 votes
responded Apr 10, 2018 by LC Marshal Captain (25,790 points)
edited Oct 31, 2018 by LC Marshal
// Add id attribute to element
$(detailcontent).attr('id', 'property-detail-content'); 
0 votes
responded May 4, 2018 by LC Marshal Captain (25,790 points)
edited Oct 31, 2018 by LC Marshal
//Manipulate attr for img source
$('#arrow-3').attr('src','https://yoursite.com/images/arrow_down.png');
0 votes
responded May 4, 2018 by LC Marshal Captain (25,790 points)
edited Oct 31, 2018 by LC Marshal
//Change hyperlink value
$("#link").attr('href', 'https://hormart.com');
0 votes
responded May 7, 2018 by LC Marshal Captain (25,790 points)
edited Oct 31, 2018 by LC Marshal
// attribute for data
var hormatLink = $('.header-nav a[href="http://hormart.com/"]');
hormatLink .attr("data-placement","bottom");
0 votes
responded Oct 31, 2018 by LC Marshal Captain (25,790 points)
// change href attr to new value
(function() {
    $(document).ready(function() {
        var a = $("#checkin").attr("href");
        $("#sidr ul li:eq(2) a").attr("href", a)
    })
})();

 

lazacode.org - Malaysia's programming knowledge sharing platform, where everyone can share their finding as reference to others.
...