0

I've a simple page with link_to_remote Rails Ajax function and HTML table. I'd like to change row of the table when click that link.

This is my html.

<table border="1">
    <tr>
        <td><div id="ajax_result_1">1</div></td>
        <div id="ajax_result_2"><td>2</td></div>

    </tr>
    <div id="ajax_result_3">
    <tr>
        <td>3</td>
        <td>4</td>
    </tr>
    </div>
</table>

And this is my code.

<%= link_to_remote 'Change', :update => "ajax_result_1", :url => "change_path" %>

change action just render simple text.

When I use ajax_result_1 for :update, it worked okay.

But, not for ajax_result_2 and ajax_result_3.

Is there a way to solve this? I want to replace row of the table.

1 Answer 1

1
<div id="ajax_result_2"><td>2</td></div>

this should be

<td><div id="ajax_result_2">2</div></td>

and

<div id="ajax_result_3">
<tr>
    <td>3</td>
    <td>4</td>
</tr>
</div>

should be

<tr  id="ajax_result_3">
    <td>3</td>
    <td>4</td>
</tr>

you cann't use <div> tag in table directly if you want to use <div> you have to use it in the <td> only.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! I thought that id attribute is only valid in div tag!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.