jQuery .html() method to replace element

0 votes
702 views
added Mar 28, 2018 in jQuery by anonymous
edited Mar 21, 2019 by LC Marshal

Find element and add/change html of it

$('#area-outlook-link').html('<a href="http://google.com">Google</a>');

7 Responses

0 votes
responded Apr 5, 2018 by LC Marshal Captain (25,790 points)
edited Apr 6, 2018 by LC Marshal

Click element, and change element with .html() method

$("button").click(function(){
    $("p").html("Hello <b>world</b>!");
});
0 votes
responded Apr 5, 2018 by LC Marshal Captain (25,790 points)
edited Apr 6, 2018 by LC Marshal

Change #regTitle element wih .html() method for JS & jQuery

document.all.regTitle.innerHTML = 'Hello World';
$("#regTitle").html("Hello World");
0 votes
responded Apr 9, 2018 by LC Marshal Captain (25,790 points)
edited Oct 2, 2018 by LC Marshal
<a id="search-listing" target="_blank" href="/map-search-property?&keyword=">
  <button class="button white">Search for listings</button>
</a>


<script>
    //jQuery
    var projectname = $('h1.page-header').text();
    var x = "/map-search-property?&keyword=";
    var y = projectname.substr(0, projectname.indexOf(','));
    var result = x + y;

    $('a#search-listing').attr('href', result);
</script>
0 votes
responded Apr 20, 2018 by LC Marshal Captain (25,790 points)
edited Oct 2, 2018 by LC Marshal

Change content of element with other element

var header = $('h1.page-header'),
    forumQ = $('.field-type-text-with-summary > .field-items');

$(header).html(forumQ);
0 votes
responded Apr 26, 2018 by LC Marshal Captain (25,790 points)

Replace .forum-category element with forumSubCat

var forumSubCat = $('ol.breadcrumb li:nth-child(3) a');
$('span.forum-category').html(forumSubCat);
0 votes
responded Oct 2, 2018 by LC Marshal Captain (25,790 points)
var i1 = $('.category-icon-title.card-1'),
      i2 = $('.category-icon-title.card-2'),
      i3 = $('.category-icon-title.card-3'),
      iPlacement1 = $('li.col-md-4.with-icons:first-child #el-icon'),
      iPlacement2 = $('li.col-md-4.with-icons:nth-child(2) #el-icon'),
      iPlacement3 = $('li.col-md-4.with-icons:nth-child(3) #el-icon');

$(iPlacement1).html(i1);
$(iPlacement2).html(i2);
$(iPlacement3).html(i3);

 

0 votes
responded Oct 30, 2018 by LC Marshal Captain (25,790 points)
(function($){
    $(document).ready(function(){
      $(".module.odd.p-t-30.p-b-40 .block-editors-pick:nth-child(2) .block-content .i-row .col-sm-6:nth-child(2)")
        .html('<div style="width: 300px;height: 250px;"><a href="/pullout"><img src="https://files.theedgeproperty.com.my/public/images/pullout1.png" style="width: 300px;height: 250px;"></a></div>');
    });
})(jQuery);

 

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