1
votes

I have the following HTML

<input type="submit" name="cm-ajax-submit" value="Register">

I need to append a div tag so it'll have this format

<input type="submit" name="cm-ajax-submit" value="Register"><div id="cmprivacy"></div>

Is there a way to use jQuery append or another function to find the input with the name cm-ajax-submit and append that div?

Thanks

3

3 Answers

12
votes

Create the element and move it using .after,

$('input[name=cm-ajax-submit]').after('<div id="cmprivacy"></div>');
5
votes

Use the .after function, not .append.

html:

<input id="button" type="submit" name="cm-ajax-submit" value="Register">​

jQuery:

$('#button').click(function() {
    $(this).after('<div id="cmprivacy">Hey</div>');
});​

http://jsfiddle.net/sfsWC/

2
votes

Try this.. Use .after() method

$('input[name="cm-ajax-submit"]').after('<div id="cmprivacy"></div>')