0

Hi I have a piece of jquery that dynamically creates an unordered list:

var get_url = "<?php echo base_url(); ?>index.php/notes/get/"+<?php echo $id;?>;

$.get(get_url, function(data) {

$.each(data,function(index, arr)
   {
      var opt = $('<li />'); 

      opt.text(arr['body']);
      $('#notes-list').append(opt);
   });
});

This produces the correct list but I want to add < pre> tags around the text in the list item.

Can someone point me in the right direction?

I've tried opt.innerHTML = "< pre />"; but no luck.

Thanks,

Billy

2 Answers 2

2

You could just append the HTML instead of an object.

var get_url = "<?php echo base_url(); ?>index.php/notes/get/"+<?php echo $id;?>;

$.get(get_url, function(data) {
    $.each(data,function(index, arr){
       var html = '<li><pre>' + arr['body'] + '</pre></li>';
       $('#notes-list').append(html);
    });
});
Sign up to request clarification or add additional context in comments.

Comments

0

try this (which involves appending a $('<pre>') element to ur obt element):

var get_url = "<?php echo base_url(); ?>index.php/notes/get/"+<?php echo $id;?>;

$.get(get_url, function(data) {
$.each(data,function(index, arr)
   {
      var opt = $('<li>'); 
      var text = $('<pre>', {text: arr['body']})
      opt.append(text);
      $('#notes-list').append(opt);
   });
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.