Last active
December 17, 2015 00:19
-
-
Save achudars/5520470 to your computer and use it in GitHub Desktop.
Get all links within a container and to convert it to a dropdown list with redirection using jQuery
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* use : $(selector).convertToList() | |
it's better to follow it with .remove() to remove the original container */ | |
(function ($) { | |
$.fn.convertToList = function () { | |
var that = this; | |
this.before( | |
$('<select><option>Please select</option></select>'). | |
change(function () { | |
window.location = $(this).val(); | |
})) | |
this.find('a').each(function () { | |
that.prev('select').append('<option value="' + $(this).attr('href') + '">' + $(this).html() + '</option>') | |
}); | |
}; | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment