Reputation: 2271
I have an html link created using
<?php
echo $html->link(
'Save Form',
array('action'=>'/homepage', $userid),
array('class'=>'button','id'=>'saveForm'),
'really save the Form ?',
false
);
?>
And I want this link to append it to #save
using jQuery
How could I append this link to an id using jQuery. Something like the following:
$("<input id='saveForm' type='Submit' class='button' value='Save Form'>")
.appendTo("#fb_contentarea_col1down2 #save");
Upvotes: 1
Views: 470
Reputation: 8701
Your problem, I guess, is that you're not getting an id
in the generated link (This is cakePHP, right?)
So, I guess you'd better use the contains
jQuery selector like this:
$("a:contains('Save Form')").appendTo('#saveForm');
Upvotes: 1
Reputation: 22438
If I understand what you are after it would be
$('#saveForm').appendTo('#save');
That takes the saveForm
element and sticks it after save
element on the DOM
Upvotes: 1
Reputation: 33295
If you want to use PHP to generate some HTML that you want to append using jQuery, you would need to do some AJAX. In this case using $.get() would probably be the best option. This will enable your jQuery script to get some data (the HTML to insert) through an URL. Then all you would need to do would be to process and append the data. Something like this should work.
$.get('the.url', {'optional': 'parameters'}, function(data) {
// data will hold what was outputted by the PHP on visiting the url.
$("selector").append(data);
});
Upvotes: 2