Reputation: 15836
I have a div that I want to append dynamic elements inside , these elements are just divs that have specific classes , and some custom attribute called tag , the function works fine , but for some elements it just acts weird , here is an example : to append a div that will show operator "=" , and have tag attribute equal to "" , i use :
$("#Add_equal").click(function(){
$("#rule_assembly").append('<div tag="<equal></equal>" class="block operator">=</div>')
and it works fine.
to use same algorithm to append a div that will show operator "/" , and have tag attribute equal to "" , i use:
$("#rule_assembly").append('<div tag="<expr operator="/"></expr>" class="block mathoperator">/</div>')
this one doesn't work it is supposed to show "/" but it doesnt !! any help would be appreciated .
JSFIDDLE : http://jsfiddle.net/prollygeek/eQYdn/
try pressing equal button , and division button.
Upvotes: 2
Views: 3028
Reputation: 231
You've got some weirdness going on with your single and double quotes so the string is concatenating incorrectly. Try the following for the / div instead of what you've got:
$("#rule_assembly").append('<div tag="<expr operator=' + '/' + '></expr>" class="block mathoperator">/</div>');
Hope that helps!
Upvotes: 0
Reputation: 95022
your attribute is invalid, it's wrapped in double quotes and contains double quotes. You must escape the inner quotes.
'<div tag="<expr operator="/"></expr>" class="block mathoperator">/</div>'
Upvotes: 4