Nathan Riley
asked on
Optimize jQuery
Is there a better way to write the below so I don't need 2 on click commands?
$("#lockSelection").click(function() {
$("#lockSelection").toggle();
$("#unlockSelection").toggle();
})
$("#unlockSelection").click(function() {
$("#lockSelection").toggle();
$("#unlockSelection").toggle();
})
This is strange you should not need it set up like that. Why is there two different id's here can you elaborate on what you are doing.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Here is the HTML, hope that helps.
<div id="lockSelection" class="text-center" style="margin-top:15px;cursor:pointer;"><i class="fa fa-lock"></i> Lock Selection</div>
<div id="unlockSelection" class="text-center" style="margin-top:15px;cursor:pointer;display:none;"><i class="fa fa-unlock"></i> Unlock Selection</div>
Ok, so my solution might be the best option.
You can even use the same event handler if you want to do something else other that just show/hide the div's.
Do this by using the :visible selector to evaluate which is actually visible after the toggles.
You can even use the same event handler if you want to do something else other that just show/hide the div's.
Do this by using the :visible selector to evaluate which is actually visible after the toggles.