jQuery .html() method to replace element

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

Find element and add/change html of it

  1. $('#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

  1. $("button").click(function(){
  2. $("p").html("Hello <b>world</b>!");
  3. });
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

  1. document.all.regTitle.innerHTML = 'Hello World';
  2. $("#regTitle").html("Hello World");
0 votes
responded Apr 9, 2018 by LC Marshal Captain (25,790 points)
edited Oct 2, 2018 by LC Marshal
  1. <a id="search-listing" target="_blank" href="/map-search-property?&keyword=">
  2. <button class="button white">Search for listings</button>
  3. </a>
  4.  
  5.  
  6. <script>
  7. //jQuery
  8. var projectname = $('h1.page-header').text();
  9. var x = "/map-search-property?&keyword=";
  10. var y = projectname.substr(0, projectname.indexOf(','));
  11. var result = x + y;
  12.  
  13. $('a#search-listing').attr('href', result);
  14. </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

  1. var header = $('h1.page-header'),
  2. forumQ = $('.field-type-text-with-summary > .field-items');
  3.  
  4. $(header).html(forumQ);
0 votes
responded Apr 26, 2018 by LC Marshal Captain (25,790 points)

Replace .forum-category element with forumSubCat

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

 

0 votes
responded Oct 30, 2018 by LC Marshal Captain (25,790 points)
  1. (function($){
  2. $(document).ready(function(){
  3. $(".module.odd.p-t-30.p-b-40 .block-editors-pick:nth-child(2) .block-content .i-row .col-sm-6:nth-child(2)")
  4. .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>');
  5. });
  6. })(jQuery);

 

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