What is the best method to choose the following sentence once the final * has been identified

In the navigation text, my objective is to pick out the final sentence following *

For example;

Home*Development*Mobil and Web Development

I am only interested in selecting the last sentence after * --> (Mobil and Web Development)

Answer №1

To extract the text Mobil and Web Development from a given string, you can utilize the method .split(/[*]+/).pop().

Example

var result = "Home*Development*Mobil and Web Development".split(/[*]+/).pop();
console.log(result)

Answer №2

To achieve this, you can utilize Regular Expressions in JavaScript

let example = "Home*Development*Mobil and Web Development";

let regexPattern = /.*\*(.*)$/

let results = example.match(regexPattern);

console.log(results[1]);

Answer №3

If you're looking to add some styling specifically to the last part of a sentence, one approach is to utilize JavaScript to target elements with a specific class on page load, extract the final portion, wrap it in a span element, and style it accordingly:

const selectLasts = document.querySelectorAll('.selectLast');

selectLasts.forEach(selectLast => {
  const text = selectLast.innerHTML;
  const arr = text.split('*');
  const lastText = arr.pop();
  selectLast.innerHTML = arr.join('*');
  const lastEl = document.createElement('span');
  lastEl.innerHTML = '*' + lastText;
  selectLast.appendChild(lastEl);
});
.selectLast span {
  background-color: yellow;
}
<div class="selectLast">Home*Development*Mobil and Web Development</div>

Answer №4

To add a child element within a div, simply nest it inside as shown below and apply CSS styling accordingly.

div > span {
color:blue;
}
<div>
Website "" Designing "" <span>Graphic and UI Design</span>
</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

Tips for customizing a dropdown menu where the first item is not the label and may include an input field

How can I create a dropdown box that includes a label of "select so and so..." and when the user clicks on it, a list of options is displayed with the first option being blank instead of showing the label name? Is it possible to include an input box insi ...

Using JSTL with jQuery or JavaScript

I am trying to send array elements from my Java code to a JSP page. The goal is for the array elements to be displayed on the page when a button is clicked. I have attempted to use the JSTL forEach tag within JavaScript or jQuery, but unfortunately, it do ...

data-type="search" fields and the pre-set input text

Upon inspecting the HTML code generated by jQuery Mobile, I noticed: <input placeholder="Filter Items..." data-type="search" class="ui-input-text ui-body-b"> I tried to modify this value with the following code: $("ul[data-filter='true'] ...

Discover the significance of a data attribute's value for effective comparisons

I have a loop that generates random numbers and positions to create 4 answer choices for users. Now, I am trying to determine the value of the clicked button and compare it to the position of the correct answer. However, whenever I try to do this, it retu ...

Updated INNER header and footer - unrelated to the answered questions

After observing, the inner-header and inner-footer div scroll along with the area that contains the select list. How can I make that area scroll down while keeping the inner-header/footer fixed within the content? I hope my query is understandable. Thank ...

Node.js does not support running Bootstrap and CSS, resulting in style not being applied due to the MIME type ('text/html') not being a supported stylesheet MIME type

I attempted to test out the Start Bootstrap Bare template using Node.js and Express. (Link to Start Bootstrap Template) I opted not to make any alterations to the HTML, CSS, and JavaScript files provided with the template. Instead, I created a new index.j ...

I seem to be overlooking a simple jQuery code as someone new to jQuery

Is there a way to use jquery to insert a div after every dd tag in a document? $(document).ready(function(){ $('dd').xyz('<div class="clear"></div>'); // how can we define this xyz function? }); Consider the following ...

Next/image is encountering an error due to an invalid Element type being generated

Trying to utilize the next/image feature to display an SVG image is causing me some trouble. Every time I attempt this, an error message pops up: Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite ...

There are additional elements that can be toggled, but I prefer to only toggle the one that I have selected

Every time I click on a table a, intending to toggle the .info inside the same div, it also toggles the .info in other divs. Can someone provide assistance with this issue? function info() { $('.table a').click(function() { $('.info ...

What is the best way to incorporate TypeScript into a simple JavaScript project and release it as a JavaScript library with JSDoc for TypeScript users?

Issue: I have encountered difficulties finding an efficient solution for this. Here's a summary of what I attempted: To start, ensure that allowJs and checkJs are both set to true in the tsconfig.json, then include the project files accordingly. Ty ...

Odd Behavior when altering button attribute using Jquery

After disabling a button with a click handler, I have noticed an interesting behavior where the button does not submit afterwards. The issue seems to vary between different browsers, with Firefox still allowing form submission after the button is disabled, ...

Facing issues using Angular 5 for PUT requests due to 401 errors

When attempting to update data using the PUT Method in my angular service and express routes, I encountered a 401 error. Here is my service code: //401 makeAdmin(_id) { this.loadToken() let headers = new Headers() headers.append('Authorization& ...

Looking to locate or track duplicate values within a multi-dimensional array?

In a multidimensional array, I am looking to detect and count duplicates. If duplicates are found, an alert should be triggered. Arr =[[2,"sk"],[3,"df"],[7,"uz"],[3,"df"],[7,"gh"]] Suggestions: One way to ...

Using jQuery to target a specific HTML element by its ID, not requesting the entire webpage

Currently, I am attempting to utilize jQuery ajax to fetch a project page. In this scenario, the xhr variable is expected to hold the correct string to the webpage (the target page). I have set up a condition to prevent the page from loading as a mobile v ...

What is the reason in AngularJS for requiring directive attributes to be hyphen-separated while their scope variables are camelCased?

Here is an example in Html: <!-- Note 'display-when' is hyphenated --> <wait-cursor display-when="true"></wait-cursor> Then, when defining it in the directive: scope: { // Note 'displayWhen' is camelCased show: ...

Adjusting Media Queries according to the browser window's zoom level

Is there a way to detect the browser width dynamically? For instance, can I adjust the CSS styling based on zoom adjustments like ctrl + or ctrl -? By "box," I am referring to a perfectly square shape. So, when the browser width is 100%, I want a layout wi ...

Send PS3 through user agent for redirection

If a user is accessing the site using a PS3, I want them to be redirected to a different webpage Below is the code snippet I have been attempting to use: <script language=javascript> <!-- if ((navigator.userAgent.match(/iMozilla/i)) || (navigato ...

jQuery failing to trigger onClick event for a specific group of buttons

Javascript: <script> $(document).ready(function(){//Implementing AJAX functionality $(".acceptorbutton").on('click', function(){ var whichClicked = this.attr('name'); ...

Encountered an error while trying to create a new NestJS project using yarn: Command execution failure - yarn install --

Having trouble installing a new NestJs project using yarn. Operating system : Microsoft Windows [version 10.0.19044.3086] Node version : 18.17.1 npm version : 9.6.7 yarn version : 1.22.19 Nest cli version : 10.1.16 I attempted to install by running : npm ...

Modifying the attribute of an element inside an array

Presented below is an object: { "_id" : ObjectId("5a8d83d5d5048f1c9ae877a8"), "websites" : [ "", "", "" ], "keys" : [ { "_id" : ObjectId("5a8d83d5d5048f1c9ae877af"), "name ...