Я хочу переключить видимость 2 ссылок (send_email
и email_sent
) в таблице в моем приложении rails. Обе ссылки находятся в одной ячейке.Как добавить и удалить имя класса из ссылки при нажатии?
<table >
<% @applications.each do |application| %>
<tr>
<td>
<a href="mailto:[email protected]" class="send_email">Invite for an interview</a>
<a href="" class="email_sent hidden">Undo</a>
</td>
</tr>
<% end %>
</table>
В моей CSS У меня есть
.hidden{display: none;}
Вот мой Javascript
<%= javascript_tag do %>
$(function(){
$('.send_email > a').click(function(){
// add the hidden class to send_email
// remove the hidden class from the next email_sent link
});
$('.email_sent > a').click(function(){
// add the hidden class to email_sent
// remove the hidden class from the previous sent_email link
});
});
<% end %>
Вы можете просто использовать '.hide()' и '.show()', зачем с классами? – Barmar
Вы правы. Мой js сосет. Как вы идентифицируете ссылку 'sent_email' для показа? – grabury
Используйте '.next()' и '.prev()' – Barmar