Category: JavaScript

  • Simpliest way to obfuscate e-mail address using jQuery

    Simpliest way to obfuscate e-mail address using jQuery

    Here is a simpliest jQuery code to protect e-mail addresses on your website from spam bots. Just put this in a script tag into the head section: $(window).load(function() { // anti spam var r=’random-string’; $(‘.’+r).each(function() { var $this = $(this), value = new String($this.text()); value = value.replace(‘[‘+r+’]’, ‘@’); $this.replaceWith($(”).text(value).attr(‘href’, ‘mailto:’+value)); }); }); Now replace random-string with any […]

  • How to programmatically select option in a HTML list using jQuery?

    How to programmatically select option in a HTML list using jQuery?

    This is very simple solution to select specified option in a HTML select list. You just need to use the val function on a select element to set it’s value. It’s simple like that: $(‘select#identificator’).val(‘value of existing option value’); Check working example on the JSFiddle: http://jsfiddle.net/fedek6/B3Ehj/

  • How to check visibility state in jQuery toggle function?

    How to check visibility state in jQuery toggle function?

    Here is a quick tip how to check visibility state of a toggled element in jQuery: $(‘#element’).toggle(‘slow’, function() { if($(this).is(‘:hidden’)) { $(this).text(‘This element is hidden.’); } else { $(this).text(‘This element is visible.’); } });