0

I'm trying to handle the content of a bunch of divs with jQuery. It works perfectly except for the fact that when the HTML is placed inside a visible div it won't render elements like <h3> or <br> as HTML, they just end up being displayed as code. Any thoughts? I've tried messing around with Rails' h(this) or this.html_safe, neither of which seem to work.

This code makes the hidden 'storage' divs:

<div style="display: none;"><%= content_tag(:div, r.body.html_safe, :id => 'page'+i.to_s+'_hidden_article'+r.issue_id.to_s) %></div>

This code displays one of the above to the user:

<%= content_tag(:div, "", :id => "document_article#{i}_body", :class => "thumbnail") %>

And this is the jQuery that manages it the exchanges:

$('#doc_article1').change(function() {
  var src = $(this).val();
  $('#document_article1_body').text('');
  var b = $('#page1_hidden_article'+src).text();
  $('#document_article1_body').text(b);
});

Any help would be excellent.

Cheers!

1 Answer 1

1

Replace text() with html() may help you solve this problem.

Sign up to request clarification or add additional context in comments.

1 Comment

That was so simple! Ha. Thank-you.

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.