I am having problem with getting parameter from javascript onClick function
title = \"as\"
$(\'
Try this way :
hello = 'anything';
$('<li onClick=pushRight("'+hello+'") class="item"></li>')
title = "as"
$('<li onClick="pushRight("'+hello+'")" class="item"></li>')
See the added double quotes. "'+hello+'"
Also double quotes over your pushRight
function.
Your code won't work because it render an invalid html as shown below.
<li onClick=pushRight(as) class="item"></li>
See, there were no quotes before and after pushRight, also before and after your string
"sa"
. Know the mistake and correct. Using inline js with html is not recommended.You have to bind events in these scenarios.
Please don't use inline js (onlick in your html).
See reasons not to use inline js here: https://www.google.com/search?q=Why+is+inline+js+bad%3F
Here's a proper way with jQuery:
var $myElem = $('<li class="item"></li>');
$myElem.click(function() {
pushRight('hello');
});
And it's quite easy even without jQuery:
var myElem = document.createElement('li');
myElem.className = 'item';
myElem.addEventListener('click', function() {
pushRight('hello');
});
Live demo here: http://jsbin.com/uDURojOY/1/edit