Skip to content
Advertisement

How Can I Show html entities contained alert(); with Jquery?

I have json array Which contains value like

[0=>'<script>alert();</script>',1=>'test',...etc]

This array is generating from Mysql DB content.

I want to show the same text (<script type="text/javascript">alert();</script>) without executing JS with a select option each function.

Please help me.

Advertisement

Answer

$.each(JSON.parse(response_json), function (index, value) {
                var short_txt = $("<div></div>").text(value.value_name).html();
                var long_txt = $("<div></div>").text(value.long_text).html();
                $html += '<li onclick="selectSuggestion_template('' + escape(value.value_name) + '',' + val_id + ','' + escape(value.long_text) + '');">' + short_txt + ' - ' + long_txt + '</li>';
            });
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement