views:

53

answers:

2

I want to add a hidden input after some element. I am using this code:

$("<input type="text">").insertAfter(".addProduct");

It doesn't work. But if I replace to it works.

$("<span>ddd</span>").insertAfter(".addProduct");

It works. Help me.

Thank you.

+1  A: 

You should use single quotes:

$('<input type="text" />').insertAfter('.addProduct');
Darin Dimitrov
No. It doesn't work.
Alexander.Plutov
@Alexander.Plutov Yes it does. However, if you're generating it by means of PHP or the like, the quoting may collapse with the one used by PHP.
jensgram
I have tried this code. It doens't work.
Alexander.Plutov
Then either the `.addProduct` element you expect does not exist or is hidden or the problem lies somewhere else.
Shrikant Sharat
Lol. See my answer. It works. But your code doesn't.
Alexander.Plutov
+1  A: 

If you create this script in php, use this:

$("<input type=\"text\">").insertAfter(".addProduct");
Alexander.Plutov