The forum of the forums
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Please help me with the author's background color

3 posters

Go down

Solved Please help me with the author's background color

Post by zzlasperpen October 24th 2023, 8:38 am

That means I need a script that when the author writes a post, there will be a separate background color. When other members comment on the post, there will be no background color, only the author who wrote the post will have it.


Last edited by zzlasperpen on October 24th 2023, 1:22 pm; edited 1 time in total
zzlasperpen
zzlasperpen
Forumember

Male Posts : 55
Reputation : 3
Language : VietNam

https://raovat24.forumvi.com/

Back to top Go down

Solved Re: Please help me with the author's background color

Post by Razor12345 October 24th 2023, 9:03 am

Good morning!

Are you talking about this forum: https://raovat24.forumvi.com ?
Give a link to the thread so that it has multiple replies from different users.

And a clarifying question - do you want all author's posts to have a certain color (not just the first one)?



Please help me with the author's background color Screen51
Razor12345
Razor12345
Support Moderator
Support Moderator

Male Posts : 1542
Reputation : 266
Language : Ukr, Rus, Eng
Location : Ukraine

Back to top Go down

Solved Re: Please help me with the author's background color

Post by zzlasperpen October 24th 2023, 10:20 am

Hello @Razor12345 .That's my forum link
Please help me with the author's background color Untitl11
This is the image of the author posting (I have circled it in red), which means I want the author of the post to have a different background color than the commenting members.
zzlasperpen
zzlasperpen
Forumember

Male Posts : 55
Reputation : 3
Language : VietNam

https://raovat24.forumvi.com/

Back to top Go down

Solved Re: Please help me with the author's background color

Post by Razor12345 October 24th 2023, 12:23 pm

Since you have heavily modified templates, I can't test my code on my test forum. I can only create it and test it through the developer tools on your forum.

AP - Modules - Javascript codes management - Create a new JavaScript

Title: any
Placement: In the topic
Code:

Code:
$(document).ready(function() {
const listOfMessages = document.querySelectorAll('.post-wrap');
if (listOfMessages) {
const authorOfArticle = listOfMessages[0].querySelector('.post-inner .post-cell.post-header-user .post-user .post-author-more .post-userName .post-author-name .authorid').innerText;

listOfMessages.forEach((item) => {
    const authorOfPost = item.querySelector('.post-inner .post-cell.post-header-user .post-user .post-author-more .post-userName .post-author-name .authorid');
    if (authorOfPost) {
    const authorOfPostName = authorOfPost.innerText;
    if (authorOfPostName === authorOfArticle) {
    item.querySelector('.post-inner .post-cell.post-main').style.background = '#eee';
    }
    }
});
}
});

Result:

Please help me with the author's background color Scree459

Please help me with the author's background color Scree460

To change the background color, in this line

Code:
item.querySelector('.post-inner .post-cell.post-main').style.background = '#eee';

Replace this code
Code:
#eee
with the color code you need.


Please help me with the author's background color Screen51
Razor12345
Razor12345
Support Moderator
Support Moderator

Male Posts : 1542
Reputation : 266
Language : Ukr, Rus, Eng
Location : Ukraine

SarkZKalie, TonnyKamper and zzlasperpen like this post

Back to top Go down

Solved Re: Please help me with the author's background color

Post by zzlasperpen October 24th 2023, 1:22 pm

tks @Razor12345 it works perfectly Please help me with the author's background color 1f60d Please help me with the author's background color 1f60d Please help me with the author's background color 1f60d
zzlasperpen
zzlasperpen
Forumember

Male Posts : 55
Reputation : 3
Language : VietNam

https://raovat24.forumvi.com/

Razor12345 likes this post

Back to top Go down

Solved Re: Please help me with the author's background color

Post by skouliki October 24th 2023, 1:31 pm

Problem solved & topic archived.
Please read our forum rules: ESF General Rules
skouliki
skouliki
Manager
Manager

Female Posts : 15241
Reputation : 1702
Language : English,Greek
Location : Greece

http://iconskouliki.forumgreek.com

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum