0

I want to call or execute javascript function when user click on image. I have javascript file with many functions and one of them is ShowKeybord(). So i want to execute this function ShowKeybord() when user clicks on image.

I tried with HTML parameter onclick: <img src = "' + content + '" alt = "Heads" onclick = "ShowKeyboard()" height="170" width="170"/> but its not working.

Here is my code of key functions that are related to my problem.

enter image description here

I tried with header.addEventListener('click', ShowKeyboard) and work properly but the keyboard is displayed when you click anywhere in the header of the web page. I would however like to make the keyboard appear only when a user clicks on the image.

What am I doing wrong and what should change depending on my code?

Thank you very much for your help.

3 Answers 3

2

You can also try to encapsulate your img with a div with the attribute onclick="ShowKeyboard()"

Wich gives something like this

<div onclick = "ShowKeyboard()">
<img src = "' + content + '" alt ="Heads" height="170" width="170"/>
</div>
Sign up to request clarification or add additional context in comments.

Comments

1

It's better to enclose your image inside a div tag. As suggested by @Lucas Duval. This should definitely work if not please give your div an "ID" or "class" and try to handle this with JQuery.

Thanks!

Comments

1

in the head tag put

<script src="yourjavascriptfilepath"></script>

and should work.

or maybe try onclick="ShowKeyboard()" rather than onclick = "ShowKeyboard()"

I think that has to do something with it.

1 Comment

I already have link to javascript file in my index.html and there is nore diference between onclick="ShowKeabord() and onclick = "ShowKeybord()"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.