Thay đổi văn bản trong thẻ CODE thành địa chỉ liên kết

Updated on May 15, 2016
Trong ví dụ này, bạn sẽ làm cho mọi văn bản trong thẻ <code> bên trong một vùng <div> trở thành một từ khóa cho các trang kết quả tìm kiếm trên trang web của bạn
Lưu ý là Template đã được cài thư viện Jquery
Javascript:
<script>//<![CDATA[
$(function() {
  $('div.post-body').children('code').each(function() {
     $(this).replaceWith(function() {
        return $('<a href="https://tipscopy.blogspot.com/p/search-results.html?q=' + $(this).text() + '" target="_blank" title="Tìm từ khóa này"><code>' + $(this).html() + '</code></a>');
     });
  });
});
//]]></script>
HTML
<div class="post-body">
     Thủ thuật <code>Blogger</code>
</div>
Demo:
Share this: pinterest