Creating a div with onclick inline that uses a class

The name of the picture


Creating a div with onclick inline that uses a class



So a bit of a seemingly complicated div Im trying to make, mostly because of the CMS I am using (that doesnt allow JS in the editor, but does allow inline js).



Im creating a clickable div that goes to a website.


<div onclick="location.href='http://www.google.com';">THIS IS MY LINK</div>



There is also a class that's being used on the backend that allows any link tag to open a lightbox. Everything works seemlessly using that method, but for the sake of this specific design, a div NEEDS to be used to open a link, and the only JS that can be used must be inline.



Weird situation, I know - but my question is this. Is there a way to have that onclick open a link and also call the class that is already in use on the page? So basically clicking the div, and opening the link in the lightbox (as if it was a regular link with a class)?




1 Answer
1



You can make more than 1 command in onclick handler like so:


<div onclick="MyClass.call();location.href='http://www.google.com';">THIS IS MY LINK</div>






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Arduino Mega cannot recieve any sketches, stk500_recv() programmer is not responding

Visual Studio Code: How to configure includePath for better IntelliSense results

C++ virtual function: Base class function is called instead of derived