Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery .serialize() not a function

Why does this not work?

var me = $('#'+id);
var content = $(me).find('input').val().serialize();

I get TypeError: $(me).find("input").val().serialize is not a function

like image 864
a1337q Avatar asked Dec 05 '22 14:12

a1337q


1 Answers

Because $(me).find('input').val() is a string and not a jQuery object, it doesn't have the serialize function.

If you want to serialize the input (with its value), use $(me).find('input').serialize();

But be sure to really need it : this function is rarely useful for just one input (we generally use it for forms). If you just want the value, use $(me).find('input').val() and if you're debugging and want to inspect the element, use console.log($(me)) and open the console of your browser.

like image 77
Denys Séguret Avatar answered Dec 26 '22 06:12

Denys Séguret