Position a div element after another using the :after pseudo-element

My goal is simple to explain, but I have exhausted all my efforts trying to achieve it.
I am hoping for the ★ symbol to appear immediately after the number 06 using jQuery.

Any assistance would be greatly appreciated.

The numbers are generated by a separate function, so in the original HTML code, the .num div appears empty.

$(".like,.like-yes").insertAfter('.num');
.none{display:none}
body{font-family:Arial;font-size:5vw;}
.num{bottom:.5em;position:fixed;width:100%;text-align:center;}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class=num>01 02 03 04 05 06</div>
<div class=like>★</div><div class="like-yes none">★</div>

Answer №1

You can utilize the append() method to convert them into inline elements

  • Update in CSS

$(".num").append($('.like,.like-yes'));
body {
  font-family: Arial;
  font-size: 5vw;
}

.like,
.like-yes {
  display: inline;
}

.none {
  display: none
}

.num {
  bottom: .5em;
  position: fixed;
  width: 100%;
  text-align: center;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class=num>01 02 03 04 05 06</div>
<div class=like>★</div>
<div class="like-yes none">★</div>

  • Alternatively, modify in HTML

$(".num").append($('.like,.like-yes'));
body {
  font-family: Arial;
  font-size: 5vw;
}
.none {
  display: none;
}

.num {
  bottom: .5em;
  position: fixed;
  width: 100%;
  text-align: center;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class=num>01 02 03 04 05 06</div>
<span class=like>★</span>
<span class="like-yes none">★</span>

Answer №2

Here is an alternative solution that eliminates the need for JavaScript by using only CSS. You can customize the styling with jQuery (such as color and visibility).

.none{display:none}
body{font-family:Arial;font-size:5vw;}
.num{bottom:.5em;position:fixed;width:100%;text-align:center;}
.num:after{content:'★'}
<div class=num>01 02 03 04 05 06</div>

If you want to make the starting point clickable, simply adjust the code to fit your desired behavior when clicked:

 $(".num").append('<a href="#">★</a>');
.none{display:none}
body{font-family:Arial;font-size:5vw;}
.num{bottom:.5em;position:fixed;width:100%;text-align:center;}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class=num>01 02 03 04 05 06</div>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Handling a WCF POST request with JQuery resulting in a 400 Bad Request HTTP Response

I'm encountering an issue with my JQuery POST not being accepted by the WCF Service. Below is the JavaScript code for the POST: function jqueryPost() { var url = "/LoggingTest"; $.post(url, { message: "test message" }); } To handle the POST ...

The function data() is coming back as null

This is the code snippet I am working with: $.getJSON("link here", function (result) { $.each(result, function (i, value) { $('.usersOfGroupList').append($("<li id='userElement' data-userId='' ></li>") ...

CSS: Centralize content and use a div to hide images that overflow the container

I successfully centered my divs and images both horizontally and vertically using CSS: .center { height: 100% } .center-center { position: absolute; top: 50%; left: 50%; width: 100%; transform: translate(-50%, -50%); text-align: center; ...

Assign a value to a cookie using Node.js

I'm currently working on a web project using node.js and express. What is the best way to establish a cookie value? ...

Is there a way to conceal the second td element?

This is the code I'm using: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> </head> <body style="width:100%;" > ...

Is there a way to prevent a 'keyup' event from being triggered by a 'keydown' event?

I have a tool that resolves zip codes and I am currently utilizing a keyup event handler to trigger a server query once the input length reaches 5 characters. However, I want to prevent unnecessary calls to the script, so I am exploring the possibility o ...

Adjust the height value of each element to match the maximum height within a single line using only CSS

There are 3 divs styled with display:inline-block. I aim to adjust their height values so they match the highest one. The desired effect is demonstrated visually below. Is it doable using only CSS? ----- ----- ----- ----- ----- ---- ...

A guide on how to successfully send multiple arguments to a single Javascript method by utilizing thymeleaf onclick (th:onclick) functionality

I attempted to use the code below, but unfortunately it did not work as expected. Can you please provide me with a solution? Javascript Code ---> function passValue(id, name){ console.log(id) console.log(name) document.getE ...

Tips for resolving the warning message: "Utilize a callback function in the setState method to reference the

I'm having an issue with this code fragment as ESLint is giving me a warning: "Use callback in setState when referencing the previous state react/no-access-state-in-setstate". Can someone help me resolve this? const updatedSketch = await ImageManipula ...

Exploring the differences between the meta viewport and font size

My website includes the following code in the section: <meta name="viewport" content="width=990"/> This setting helps to display my webpage well on mobile devices, as using width=device-width causes issues with elements that have 100% width. Howeve ...

CSS Animations as an Alternative to jQuery's fadeIn(), fadeOut(), and fadeTo() Functions

I currently have the following code snippet: $('#button1').click(function(){ $('#header_bg').fadeTo(15, 0, function() { document.getElementById('header_bg').style.fill = '#FF0000'; }).fadeTo(&ap ...

Verifying if the autocomplete field is devoid of any entries

I am currently implementing the jQuery UI and utilizing the autocomplete widget. I have a button and need to determine if the user has entered any text in the autocomplete box. If not, I want to set a string to null, otherwise fetch the text and assign it ...

Determination of the winner in a tic tac toe game is not accurate using the if statement

I need some help with an issue I'm having with my code involving the "if statement". I am trying to complete my tic-tac-toe game by writing a function that determines the winner of the game. The problem arises when I try to compare the content of spec ...

How can you conceal the navigation and footer components on a 404 page using Next.js?

import Footer from "./Footer"; import Navigation from "./Navigation"; import { useRouter } from "next/router"; function CustomLayout({ children }) { const router = useRouter(); return ( <> {router.pathname ...

Utilizing React JS with Material-UI Autocomplete allows for seamlessly transferring the selected item from the renderInput to the InputProps of the textfield component

Exploring the functionality of the updated version of Autocomplete, my goal is to ensure that when an element is chosen from the dropdown menu, the input format of the text field will be modified to accommodate adding a chip with the selected text. Is the ...

Restricting the type of user input in HTML forms

Requirements: Input must be a whole number between 2 and 99, inclusive. Current Solution: <input required type="number" min="2" max="99" oninput="this.value = Math.abs(this.value)" maxLength="2" matInp ...

Implementing an object as a filter in an NG-repeat function

I've created multiple select dropdowns that are populated from a JSON file containing categories. My goal is to use the selections made by users in the dropdowns to filter a list of apps generated using ng-repeat. In my Plunker example http://plnkr. ...

Utilizing Node.js to Retrieve Data from MySQL

Hi there, I'm new to NodeJS and I'm curious about how to fetch a MySQL query like we do in PHP. $query = mysql_query("SELECT * FROM accounts"); while($fetch = mysql_fetch_array($query)) { echo $fetch['Username']; } How would this be ...

Having trouble accurately obtaining the height of a DIV element using jQuery

After trying to troubleshoot on my own, I ran into a roadblock due to my specific requirements not being met by existing solutions. The issue at hand is as follows: I have a sticky DIV element positioned to the left, nested within another DIV Element wit ...

Loop through every item in Typescript

I am currently working with the following data structure: product: { id: "id1", title: "ProductName 1", additionalDetails: { o1: { id: "pp1", label: "Text", content: [{ id: "ppp1", label: "Tetetet" ...