dot
dot

Reputation: 496

How to append content to tabel with ajax?

I need some help concerning the append call in javascript.

I have the following table in my view :

<div class="splitcontentleft">
  <table class="list user_roles">
  .........
  </table>
</div>

How should I call here the append command in my *.js.erb file?

I do the following:

$('#user_roles_table').append('<%= @roles %>');

But it didn't work. I also tested the append command at a other div tag and that works, so I reckon the failure is the pramater '#user_roles_table', or not?

Upvotes: 0

Views: 37

Answers (1)

fabianfetik
fabianfetik

Reputation: 774

$('#user_roles_table')

tells jquery to wrap an object with the id attribute "user_roles_table". You probably want to use

$('table.user_roles')

which says select an element with tag table AND a class attribute of "user_roles" or just

$('.user_roles')

if that element is the only one with that class and you're not reusing the classnames.

See here for an exhaustive list of the selectors you can use with jquery

Upvotes: 3

Related Questions