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.

Add a text under the first post?

2 posters

Go down

Solved Add a text under the first post?

Post by Mati October 24th 2023, 8:10 pm

I'm using this script to add some text under the first post on every topic page but it doesn't work.

Code:
$(function(){
$('.post:first-child').after('<div class="fs-spotlight">Hello member and welcome to Forum Services!</div>');
});


Last edited by Mati on October 28th 2023, 6:47 pm; edited 1 time in total
Mati
Mati
Active Poster

Posts : 1925
Reputation : 331
Language : HTML, CSS & JavaScript
Location : Forum Services

https://forumservice.forumotion.com/

Back to top Go down

Solved Re: Add a text under the first post?

Post by Razor12345 October 24th 2023, 8:34 pm

Good evening!

1) Because you can't work with pseudo classes in JS/jQuery
2) Because the after method inserts elements, not HTML code.

To insert HTML code you need to use the insertAdjacentHTML method, which has no analogue in jQuery

Correct code:

Code:
$(document).ready(function() {
  document.querySelectorAll('.post')[0].insertAdjacentHTML('afterend', '<div class="fs-spotlight">Hello member and welcome to Forum Services!</div>');
});

Result:

Add a text under the first post? Scree466


Add a text under the first post? Screen51
Razor12345
Razor12345
Support Moderator
Support Moderator

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

Mati, SarkZKalie and TonnyKamper like this post

Back to top Go down

Solved Re: Add a text under the first post?

Post by Mati October 24th 2023, 9:17 pm

Thanks, can you also check your pm.
Mati
Mati
Active Poster

Posts : 1925
Reputation : 331
Language : HTML, CSS & JavaScript
Location : Forum Services

https://forumservice.forumotion.com/

Back to top Go down

Solved Re: Add a text under the first post?

Post by Razor12345 October 25th 2023, 3:17 pm

Is your request complete?
if your request is complete, please mark it as Solved.


Add a text under the first post? Screen51
Razor12345
Razor12345
Support Moderator
Support Moderator

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

Back to top Go down

Solved Re: Add a text under the first post?

Post by Mati October 28th 2023, 6:48 pm

You can lock it now.
Mati
Mati
Active Poster

Posts : 1925
Reputation : 331
Language : HTML, CSS & JavaScript
Location : Forum Services

https://forumservice.forumotion.com/

Back to top Go down

Solved Re: Add a text under the first post?

Post by Razor12345 October 28th 2023, 6:57 pm

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


Add a text under the first post? Screen51
Razor12345
Razor12345
Support Moderator
Support Moderator

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

Back to top Go down

Back to top

- Similar topics

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