Add a text under the first post?
2 posters
Page 1 of 1
Add a text under the first post?
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
Re: Add a text under the first post?
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:
Result:
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:
Razor12345- Support Moderator
- Posts : 1462
Reputation : 262
Language : Ukr, Rus, Eng
Location : Ukraine
Mati, SarkZKalie and TonnyKamper like this post
Re: Add a text under the first post?
Is your request complete?
if your request is complete, please mark it as Solved.
if your request is complete, please mark it as Solved.
Razor12345- Support Moderator
- Posts : 1462
Reputation : 262
Language : Ukr, Rus, Eng
Location : Ukraine
Re: Add a text under the first post?
Problem solved & topic archived.
|
Razor12345- Support Moderator
- Posts : 1462
Reputation : 262
Language : Ukr, Rus, Eng
Location : Ukraine
Similar topics
» Change the text in the "send" button to "post" for eg in post replies SOLVED
» Change colour of category name,'topics', 'post' and 'last post' text
» Text Alignment, Post Box, Duplicate Links, & Post Icons
» Post text not showing up post new reply field
» Post Text
» Change colour of category name,'topics', 'post' and 'last post' text
» Text Alignment, Post Box, Duplicate Links, & Post Icons
» Post text not showing up post new reply field
» Post Text
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum