How would I make this jQuery shorter? I assume there must be a better way of working than this!?
(bare in mind I am new to jQuery)…
<script>
jQuery(function() {
var White = jQuery("#white").hide();
jQuery("#firstpagename").on("click", function() {
White.toggle();
});
});
</script>
<script>
jQuery(function() {
var Black2 = jQuery("#v2black").hide();
jQuery("#secondpagename").on("click", function() {
Black2.toggle();
});
});
</script>
<script>
jQuery(function() {
var Black3 = jQuery("#v3black").hide();
jQuery("#thirdpagename").on("click", function() {
Black3.toggle();
});
});
</script>
Any help or directions would be greatt as I am down to the last step on this site and want it finished 🙂
You could use some extra data attribute and an extra class on your links to make it a little shorter.
So let’s say your html looks like this:
then your jquery can rewritten like this: