randomguy
randomguy

Reputation: 12252

Why isn't this jQuery and Rails Javascript Partial working?

$("#todos").append($("<%= escape_javascript(render("todo")) %>").find("form:eq[0]").children());

I'm sure the rendered partial has a form tag and it has child content, and yet, nothing gets added into #todos.

EDIT: Here's what is rendered by escape_javascript(render("todo"))

$("#todos").append($("<div class=\'todo\'>\n  <form accept-charset=\"UTF-8\" action=\"#\" class=\"new_todo\" id=\"new_todo\" method=\"post\"><div style=\"margin:0;padding:0;display:inline\"><input name=\"utf8\" type=\"hidden\" value=\"&#x2713;\" /><input name=\"authenticity_token\" type=\"hidden\" value=\"5jeoteBl1GwCw6t4jllDRVuragGoRh3wiodOV8jMgOQ=\" /><\/div>\n    <p>make laundry<\/p>\n  <\/form>\n<\/div>\n").find("form:eq[0]").children());

Upvotes: 1

Views: 541

Answers (1)

German Rumm
German Rumm

Reputation: 5832

MaybeMost probably it doesn't work because you used square brackets instead of round ones in find()

Should be

.find('form:eq(0)').children()

Upvotes: 2

Related Questions