M
M
Morerion2016-07-22 09:32:27
Google
Morerion, 2016-07-22 09:32:27

How to convert a line of html code to js into just html?

In general, I use a database to create a chat, all the text that someone wrote is stored in me like this: (p class='uid') (text) (/p) this is necessary so that if something happens, the moderator could ban the violator, but for this he needs to know the uid that is in the class, here is my code: 994073b96c8d464692e1fc5c9d312e8a.png
however, it is output like this:
88d879b3e8064e47b08c0419f6322142.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton, 2016-07-22
@Morerion

text = name + ': ' + text + '[@Admin]';
text += '<p class=""'> + text + '</p>';
$(text).addClass(userData.uid);
ref.push({text: text});

What do we see here?
There is such a line (example):
And a class should somehow be added to this line. However, it is not known how.
This:
Won't work. This is elementary in jQuery .
Do you understand what you are doing next?
Add id:
text = name + ': ' + text + '[@Admin]';
text += '<p class=""' id="item' + userData.uid + '"> + text + '</p>';
$('#item' + userData.uid).addClass(userData.uid);
ref.push({text: text});

And it's actually better like this:
text = name + ': ' + text + '[@Admin]';
text += '<p class=""' id="item' + userData.uid + '"> + text + '</p>';
$('#item' + userData.uid).attr("data-user", userData.uid);
ref.push({text: text});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question