Monday, 15 August 2011

javascript - Appending element with space in string -



javascript - Appending element with space in string -

i appending html element using foreigobject in d3js. here's html

.html(function(d) {return "<span onclick=processparams('"+str+"')><i class='fa fa-plus-circle'></i></span>";})

the problem if str value contains space, breaks. str value of 'xyz' element,

<span onclick="processparams('xyz')"><i class="fa fa-plus-circle"></i></span>

but str value of 'xyz abc'. somehow becomes,

<span onclick="processparams('xyz" abc')=""><i class="fa fa-plus-circle"></i></span>

what doing wrong?

you need quote attributes.

your sec illustration returning html:

<span onclick=processparams('xyz abc')><i class='fa fa-plus-circle'></i></span>

since you're not quoting, value of 'onclick' ends when hits space. remainder (abc')) seen param name, no value.

try:

.html( function(d) { homecoming "<span onclick=\"processparams('"+str+"')\"><i class='fa fa-plus-circle'></i></span>"; } );

javascript html d3.js

No comments:

Post a Comment