Sorry for the long winded title. I want to be a little clearer here. The below JS code acts as a toggle to open/display a container on toggle. I need for this code to be extended so that it forces the container to close if a mouse click is placed outside of the loaded form.
the following html passes id of form to load
<span id="lr-action"><a href="#" onclick="toggle_visibility('lr-form');"><h4>Sign In / Register</h4></a></span>
function toggle_visibility(id) {
var e = document.getElementById(id);
if(e.style.display == 'block')
e.style.display = 'none';
else
e.style.display = 'block';
};
All is good. Toggle works fine. But how can I add a close form function if mouse click happens outside of form loaded?
Have tried adding a snippet for this, but faced the problem of toggle close not working while click out of form working (if that makes sense!)
Also just realized, even if my above suggestion didn’t work…when you click something to open it, that element must have a :focus on it, correct? Detect when that element loses focus.
Sorry for the delat chaps and thanks so much for your replies. After hours and hours of work, this login method wasn’t liked by a partner. So it was unfortunately scrapped. But yes Pullo, this jq event is being used in other places where your code will definitely help.