I need to know, how to fetch class name from div instead of id when using Ajax on Rails
my coding is like below,
<开发者_开发知识库;div id="test_test1" class="test">
</div>
<div id="test_test2" class = "test">
</div>
and on Controller,
page.replace_html "test_test1", "<button>Thanks</button>"
please help me to solve this problem.
Thanks
If you want replace values of all divs with class 'test' you can use from rjs this code
page.select('.test').each do |value|
value.update 'new value'
end
If only one of them - then you shouldn't do it from rjs because of class of dom element not unique. You can use link_to_remote callbacks. See docs here - http://api.rubyonrails.org/classes/ActionView/Helpers/PrototypeHelper.html#M001645
page << "$$('div.test').first.replace('<button>Thanks</button>')"
精彩评论