I'm working on a project, and we use a lot of coding languages for different parts.
I've tried to simplify the problem as much as I can, and came up with the following JSfiddle.
The problem is, I have a JSON string which I want to pass on to a JavaScript function.
If I call it from JavaScript, it's OK. But when I call it with a onmouseover
, HTML throws the error
Uncaught SyntaxError: Invalid or unexpected token
function test123(obj, e, lookupx){
console.log(lookupx);
}
test123(this, event, '{"mt:assetsys:assetuapr":{"assetmat":"material","assettag":"tag"}}');
<div>
First check the console, direct calling with js string is ok.<br>
Then:<br>
<a target='_blank' href="#" onmouseover="test123(this, event, '{"mt:assetsys:assetuapr":
{"assetmat":"material","assettag":"tag"}}');">hover this
</a>
<br>
And an error occurs
</div>
Could someone explain what the difference is between the two cases?
The onmouseover vs
The direct calling to the function.
I had the same scenario, I ended up using Template literal
Note, you have to use single quotes '
for HTML attribute value.
So your code can be re-written as follows,
<div>
First check the console, direct calling with js string is ok.<br>
Then:<br>
<a target='_blank' href="#" onmouseover='test123(this, event, `{"mt:assetsys:assetuapr":{"assetmat":"material","assettag":"tag"}}`);'>
hover this
</a><br>
And an error occurs
</div>
Link to jsFiddle
You have to escape all the quotes inside the onmousover=""
Escape them with a backslash like this \"
I'm working on my first GatsbyJS project (and hosted on Netlify) and over the past few weeks have noticed that everything is very speedy during development, but when built and hosted the pages are ...
I'm working on my first GatsbyJS project (and hosted on Netlify) and over the past few weeks have noticed that everything is very speedy during development, but when built and hosted the pages are ...
here i didn't understand what happen when i use var before variable in function it give me different out put and with out using var also i got a different output here is a code that you can easily ...
here i didn't understand what happen when i use var before variable in function it give me different out put and with out using var also i got a different output here is a code that you can easily ...
I am trying to use velocity together with jQuery (only for IE8 support) in an ES6 module. Consider this code: import { Component } from 'react'; import ReactDOM from 'react-dom'; import jquery from '...
I am trying to use velocity together with jQuery (only for IE8 support) in an ES6 module. Consider this code: import { Component } from 'react'; import ReactDOM from 'react-dom'; import jquery from '...
Firebase Cloud Messaging I have everything setup, the Push messages are received fine and when I click on it, it opens new window... but only in Chrome, in Firefox it is not opened. I have ...
Firebase Cloud Messaging I have everything setup, the Push messages are received fine and when I click on it, it opens new window... but only in Chrome, in Firefox it is not opened. I have ...