I thought this code should work but it didnt, can someone explain?
$("#addLinkLayout input.comment, #addLinkLayout input.link").each(function() {
$(this).val().appendTo('div#links');
});
It says $(this).val().appendTo()
is not a function.
appendTo
can only be applied on jQuery objects. But val
returns a string.
Try this instead:
$("#addLinkLayout input.comment, #addLinkLayout input.link").each(function() {
$('div#links').append($(this).val());
});
val()
doesn't return a DOM element. It returns the value
attribute from a DOM element. So if you have something like <input value="foo" />
, calling val() on that node will give you a string "foo"
. Since javascript's string class doesn't have a method appendTo
, you're getting an error.
You probably want something like
$('div#links').append($(this).val());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With