Monday, 2 July 2012

Auto Highlight Teks di dalam Tag PRE dengan JQuery

Auto Highlight Text Inside Pre with JQuery

Sebenarnya ini tidak mutlak pada elemen <pre>. Hanya karena selektornya saja yang berupa $('pre') jadi fungsi seleksi otomatis ini diberlakukan untuk elemen <pre>:

<script src='http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js' type='text/javascript'/></script>
<script type='text/javascript'>
$(function() {
    $('pre').click(function() {
        var refNode = $(this)[0];
        if($.browser.msie) {
            var range = document.body.createTextRange();
            range.moveToElementText(refNode);
            range.select();
        } else if($.browser.mozilla || $.browser.opera) {
            var selection = window.getSelection();
            var range = document.createRange();
            range.selectNodeContents(refNode);
            selection.removeAllRanges();
            selection.addRange(range);
        } else if($.browser.safari) {
            var selection = window.getSelection();
            selection.setBaseAndExtent(refNode, 0, refNode, 1);
        }
    });
});
</script>

cara memasang:
  • masuk akun blog anda ==>> klik menu "Template" ==>> "Edit Html" ==>> cari kode "</head>" (cara mudah: klik "ctrl+f" dan ketik kode yang anda cari) ==>Tulis kode"<script type='text/javascript'>  </script>" ==>> Paste kode yang anda copy tadi di antara tag "<script type='text/javascript'>" dan "</script>" ==>> simpan template dan selesai......!!
  •  cara lainnya masuk akun blog anda ==>> klik "Tata Letak" ==>> "Tambah Gadget" ==>> pilih "Text/Javascript" ==>> Tulis kode"<script type='text/javascript'>  </script>" ==>> Paste kode yang anda copy tadi di antara tag "<script type='text/javascript'>" dan "</script>" ==>> simpan dan selesai......!!!
Selamat mencoba.....!!!

Sumber :

DAFTAR ISI

No comments:

Post a Comment

Two Reasons why IPS is a "Must Have" for your Network

Introduction This is the third in my Security Series of Connect articles.  For more information on how to keep your enterprise environm...