+ 3
show/hide button
Hi! I tried to write a JS program where the user can hide/show an element: https://code.sololearn.com/WBLzlnMpAV5Q/?ref=app But this code seems so long for such a simple action. Do you know any better ways for this?
4 odpowiedzi
0
Learn some Jquery! with just these lines of code:
$(function () {
$('#b').click(function() {
$('#e').toggle(500);
$('#b').text('switch');
});
});
it's possible to get the same result you that got there.
Also, don't forget to use CSS to make the elements have more effect and look better.
+ 4
use jQuery instead. XD
+ 1
jQuery to toggle the button as well. :)
$(document).ready(function(){
$("#b").click(function(){
$("#e").toggle();
if ($(this).text() == "Show")
$(this).text("Hide")
else
$(this).text("Show");
});
})
0
Oh, i forgot to tell. I learned ithe basic just a few days ago, and trust me, it looks confusing at first, but after you understand how it works, it must make everything simpler haha