admin管理员组文章数量:1429633
I am trying to show/hide certain divs depending on the click of a button/link. I have done some reading on how to do this with JQuery, but it doesn't seem to be working.
edit.html.erb
<script src=".1.0.min.js"></script>
<div class="pad-bottom">
<a id="edit-profile-button" class="button default ok" href="#">
Edit Profile
</a>
<div id="profile-information" class="hidden">
<div class="row pad-top">
<div class="col-xs-6 col-sm-6 field-row">
<div class="roboto bold black field-label">
First
</div>
<%= f.text_field :first_name, class: 'field', placeholder: 'First Name'%>
</div>
</div>
</div>
<script type="text/javascript">
$(document).ready(function(event){
$('#edit-profile-button').click(function(){
event.preventDefault();
$('#profile-information').toggle();
});
});
</script>
application.css
.hidden {
display: none;
}
I can click on the link and fall into a debugger and access the two elements that I try to select in the jQuery code, but it doesn't seem do be doing anything at all, the div is never made visible.
I am trying to show/hide certain divs depending on the click of a button/link. I have done some reading on how to do this with JQuery, but it doesn't seem to be working.
edit.html.erb
<script src="http://code.jquery./jquery-2.1.0.min.js"></script>
<div class="pad-bottom">
<a id="edit-profile-button" class="button default ok" href="#">
Edit Profile
</a>
<div id="profile-information" class="hidden">
<div class="row pad-top">
<div class="col-xs-6 col-sm-6 field-row">
<div class="roboto bold black field-label">
First
</div>
<%= f.text_field :first_name, class: 'field', placeholder: 'First Name'%>
</div>
</div>
</div>
<script type="text/javascript">
$(document).ready(function(event){
$('#edit-profile-button').click(function(){
event.preventDefault();
$('#profile-information').toggle();
});
});
</script>
application.css
.hidden {
display: none;
}
I can click on the link and fall into a debugger and access the two elements that I try to select in the jQuery code, but it doesn't seem do be doing anything at all, the div is never made visible.
Share Improve this question edited Mar 30, 2017 at 16:06 Zack Herbert asked Mar 30, 2017 at 15:30 Zack HerbertZack Herbert 9601 gold badge16 silver badges40 bronze badges2 Answers
Reset to default 4Your css has an issue, hidden
is not a valid value for display. It should be:
$(document).ready(function(){
$('#edit-profile-button').click(function(){
$('#profile-information').toggle();
});
});
.hidden {
display: none;
}
<script src="https://ajax.googleapis./ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="pad-bottom">
<a id="edit-profile-button" class="button default ok">
Edit Profile
</a>
<div id="profile-information" class="hidden">
<div class="row pad-top">
<div class="col-xs-6 col-sm-6 field-row">
<div class="roboto bold black field-label">
First
</div>
<%= f.text_field :first_name, class: 'field', placeholder: 'First Name'%>
</div>
</div>
</div>
Ended using bootstrap to solve my problem (http://getbootstrap./javascript/#collapse)
edit.html.erb
<div class="pad-bottom">
<a id="edit-profile-button" class="button default ok" href="#profile-information" data-toggle="collapse" aria-expanded="false">
Edit Profile
</a>
<div id="profile-information" class="collapse">
<div class="row pad-top">
<div class="col-xs-6 col-sm-6 field-row">
<div class="roboto bold black field-label">
First
</div>
<%= f.text_field :first_name, class: 'field', placeholder: 'First Name'%>
</div>
</div>
</div>
本文标签: javascriptShowHide div element with rails view htmlerb fileStack Overflow
版权声明:本文标题:javascript - ShowHide div element with rails view html.erb file - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744678152a2619238.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论