Im trying to create a little function for my use that is suppose to get the Text of the chosen element. If the element has Math in is than my function is suppose to do the math and append to the answer to the element of your choice.
My really simple function is:
function op2(id, end){
var he = $(id).text();
$(end).html(he);
}
This would be used like this:
function la() {
op2('#default', '#here');
}
With the following html:
<div id="default">10+3</div>
<div onclick="la();">Test</div>
<div id="here"></div>
This is the problem, when its suppose to add all it is doing is adding the 10+3 to the element #here instead of displaying 13.
I know that the problem is that the browser appends the text of #default to #here like this, '10+3' but I don’t know how to change that.
Here is the demo
For this simple case, use eval() function on the content of the first element. See the link for tweaked version: http://jsfiddle.net/4DF3k/