F
F
Fedor2015-09-24 00:49:56
JavaScript
Fedor, 2015-09-24 00:49:56

How to display div using js?

There is this piece of code:

$.each(g.totals_data.manufacturers, function (f, k) {
            if (k.id) {
                h[h.length] = k.id;
                var j = $("#manufacturer_" + k.id);
                if (j.length == 0) {
                    return;
                }
                j.removeAttr("disabled");
                if (j.get(0).tagName == "OPTION") {
                    j.text($("#m_" + k.id).val() + "(" + k.t + ")")
                } else {
                    $('label[for="manufacturer_' + k.id + '"]').text($("#m_" + k.id).val() + '(' + k.t + ')')
                }
            }
        });

This line $('label[for="manufacturer_' + k.id + '"]').text($("#m_" + k.id).val() + ) outputs the following (for example): Producer1(10) I want to make it so that instead of '(' ')' there are , the problem is that I can display 'div' as text and not as html code, i.e. Manufacturer1 , and I need Manufacturer1 10 (this 10 will be framed by divs). Thank you all in advance! '(' + k.t + ')'
<div> и </div><div>10</div>

Answer the question

In order to leave comments, you need to log in

3 answer(s)
L
littleguga, 2015-09-24
@svarnoy85

so replace text with html

$.each(g.totals_data.manufacturers, function (f, k) {
            if (k.id) {
                h[h.length] = k.id;
                var j = $("#manufacturer_" + k.id);
                if (j.length == 0) {
                    return;
                }
                j.removeAttr("disabled");
                if (j.get(0).tagName == "OPTION") {
                    j.text($("#m_" + k.id).val() + "(" + k.t + ")")
                } else {
                    $('label[for="manufacturer_' + k.id + '"]').html($("#m_" + k.id).val() + '<div>' + k.t + '</div>')
                }
            }
        });

H
HoHsi, 2015-09-24
@HoHsi

Try wrapping them $(). Those.

j.text($("#m_" + k.id).val()).append( $( "<div>(" + k.t + ")</div>") );
.
In this case, JQ must convert it to a DOM element

F
Fedor, 2015-09-24
@svarnoy85

Thanks everyone, really replacing text with html is the easiest solution.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question