admin管理员组文章数量:1335419
So I created the following jquery that shows/hides a div.
$(document).ready(function(){
$("#me").hide();
$("#hide").click(function(){
$("#me").hide();
});
$("#show").click(function(){
$("#me").show();
});
});
This is some text
Hide
Show
/ It works fine. But I need to make it work so that instead of having a separate show and hide text, I need to toggle show and hide. But main problem is I dont want to have the text in the javascript file for internationalization purposes. It's ok if the text resides in the html. Can someone help me with this?
So I created the following jquery that shows/hides a div.
$(document).ready(function(){
$("#me").hide();
$("#hide").click(function(){
$("#me").hide();
});
$("#show").click(function(){
$("#me").show();
});
});
This is some text
Hide
Show
http://jsfiddle/6DTeq/7/ It works fine. But I need to make it work so that instead of having a separate show and hide text, I need to toggle show and hide. But main problem is I dont want to have the text in the javascript file for internationalization purposes. It's ok if the text resides in the html. Can someone help me with this?
Share Improve this question asked Jun 19, 2013 at 21:43 MichealMicheal 2,32210 gold badges52 silver badges96 bronze badges 1- There is a toggle function in jQuery – cssyphus Commented Jun 19, 2013 at 21:45
4 Answers
Reset to default 4Html :
<div id="me"> This is some text</div>
<div id="toggle">toggle</div>
Js:
$("#toggle").click(function(){
$("#me").toggle();
});
Demo ----->
http://jsfiddle/6DTeq/8/
Updated fiddle ----->
http://jsfiddle/6DTeq/13/
Try this
$(document).ready(function(){
$("#me").hide();
$("#hide").click(function(){
$("#me").toggle();
$(this).text(function(i, val) {
return val === 'Show' ? 'Hide' : 'Show';
});
});
});
Check Fiddle
<div id="me" style="display:none;"> This is some text</div>
<div id="clickContainer">
<div id="hide" style="display:none;">Hide</div>
<div id="show">Show</div>
</div>
$(document).ready(function(){
$("#clickContainer").click(function(){
$("#me").toggle();
$("#hide").toggle();
$("#show").toggle();
});
})
Try that:
http://jsfiddle/6DTeq/10/
$(document).ready(function () {
$("#toggle").click(function () {
$("#me").toggle();
$(this).text(function(){return $('#me:visible').length?'Hide':'Show'});
}).triggerHandler('click');
});
本文标签: javascriptjquery and css solution to toggle showhide with text in the htmlStack Overflow
版权声明:本文标题:javascript - jquery and css solution to toggle showhide with text in the html - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742386818a2465199.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论