TechnicalTophat
TechnicalTophat

Reputation: 1725

Getting raw HTML and re-rendering it as HTML

I'm creating a script to rewrite the local version of the ETrack system my college uses as it's horrific, and I have a bit of an issue with formatted text. You see, there's a div on this system with the class .visitFeedback, and in this Div it has loads of <p> tags. I want to move these paragraphs into a scrollable div due to the paragraphs overflowing normally. The only issue is, these paragraphs have HTML styling within them (<strong> etc.). I want to reserve this formatting and just add it into a scrollable Div. So far I've managed to move it over, but all the methods I've tried so far return stuff like [object HTMLParagraph] instead of the text I want. So far I've tried .get(), .html(), .text(), and a few others. Can you please help? The relevant stuff is below:

var feedbackTxt;

    $('.visitFeedback p').each(function(){
        if ($(this).hasClass('info'))
        {

        }
        else
        {
            feedbackTxt += $(this).text();
            $(this).remove();
        }
    });

    $('.visitFeedback').append('<div style="overflow-y: scroll;">' + feedbackTxt + '</div>');

Upvotes: 2

Views: 70

Answers (1)

Neirid
Neirid

Reputation: 363

Why not add overflow-y: scroll to elements with the .visitFeedback class?

$('.visitFeedback').css('overflow-y', 'scroll');

Upvotes: 4

Related Questions