Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save achudars/5520470 to your computer and use it in GitHub Desktop.
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
/* 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