Skip to content

Instantly share code, notes, and snippets.

@mephraums
Last active December 25, 2015 01:19
Show Gist options
  • Select an option

  • Save mephraums/6893666 to your computer and use it in GitHub Desktop.

Select an option

Save mephraums/6893666 to your computer and use it in GitHub Desktop.

Revisions

  1. hireSwish revised this gist Oct 18, 2013. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions gistfile1.js
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,5 @@
    //Change Element Type plugin
    //Source: http://stackoverflow.com/questions/8584098/how-to-change-an-element-type-using-jquery
    $.fn.changeElementType = function(newType) {
    var newElements = [];

  2. hireSwish revised this gist Oct 18, 2013. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion gistfile1.js
    Original file line number Diff line number Diff line change
    @@ -16,4 +16,6 @@ $.fn.changeElementType = function(newType) {
    });

    return $(newElements);
    };
    };

    //Usage: $('input[type="text"]').changeElementType('date');
  3. hireSwish revised this gist Oct 8, 2013. No changes.
  4. hireSwish renamed this gist Oct 8, 2013. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  5. hireSwish created this gist Oct 8, 2013.
    19 changes: 19 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    $.fn.changeElementType = function(newType) {
    var newElements = [];

    $(this).each(function() {
    var attrs = {};

    $.each(this.attributes, function(idx, attr) {
    attrs[attr.nodeName] = attr.nodeValue;
    });

    var newElement = $("<" + newType + "/>", attrs).append($(this).contents());

    $(this).replaceWith(newElement);

    newElements.push(newElement);
    });

    return $(newElements);
    };