2

I am trying to play a sound on event using javascript

tried this

<object height="100" width="100" data="sounds/cash.wav" id="cash"></object>

var thissound= document.getElementById("cash");
thissound.play();

and it worked. the thing is , I don't my element to show on the browser, so I tried

<object height="0" width="0" data="sounds/cash.wav" id="cash"></object>
and even
<object height="100" width="100" data="sounds/cash.wav" id="cash" style="display:none"></object>

and I got an error in the JS telling me that the element is null..

2 Answers 2

2

You can try

<object height="100" width="100" data="sounds/cash.wav" id="cash" style="visibility: hidden; white-space: nowrap;"></object>

to hide it.

Sign up to request clarification or add additional context in comments.

Comments

1

Also you can wrap the object element in a block, and hide the block.

Comments

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.