jQuery : Select All Checkbox


Yahoo! Mail and GMail both has a checkbox on top of their email list which will “checked” all chekboxes when clicked. Previously I use plain old javascript like those in this link, I just try to use jQuery to do this, its only 5 lines

$('#selectAll').click(function(event){
    $('input[type="checkbox"]').each(function(){
        this.checked = event.target.checked;
    });
});
Advertisements

jQuery – Refresh IFRAME


If the iframe was not on a different domain, you could do something like this:

document.getElementById(FrameID).contentDocument.location.reload(true);

But since the iframe is on a different domain, you will be denied access to the iframe’scontentDocument property by the same-origin policy.

But you can hackishly force the cross-domain iframe to reload if your code is running on the iframe’s parent page, by setting it’s src attribute to itself. Like this:

// hackishly force iframe to reload
var iframe = document.getElementById(FrameId);
iframe.src = iframe.src;


source:
http://stackoverflow.com/questions/4249809/reload-an-iframe-with-jquery

jQuery – Remove Extra Newline in Textarea


case:

createOnEnter: function(e) {
  if (e.keyCode == 13) {
    items.create(this.newAttributes());
    this.$("#create-item :input").val('');
    this.$("#create-item :input")[0].focus();
  };
},

solution:

Default behaviour of the Enter key in a textarea is to add a new line. To prevent this action occurring within the createOnEnter method, add e.preventDefault(); after matching the key press as the Enter key.

createOnEnter: function(e) {
          if (e.keyCode == 13) {
            e.preventDefault();
            items.create(this.newAttributes());
            $("#create-item :input").val('');
            $("#create-item :input")[0].focus();
          };
        }


source:
http://stackoverflow.com/questions/4299533/how-do-i-remove-the-extra-newline-in-textarea-after-clearing-it-with-jquery-val