Organizational Research By

Surprising Reserch Topic

Question:jQuery - how to remove characters inside span tag



asked Sep 13, 2013 in jquery by anonymous
edited Sep 12, 2013
0 votes
28 views



Related Hot Questions

6 Answers

0 votes
That's because your replace function doesn't find the desired string, your title is Superlong Sites' Title - and you are trying to replace Superlong Site's Title-.

$(document).ready(function() {
  $('#current_url').text(function(){
     return $('title').text().replace("Superlong Site's Title - ", '');
  })
});
answered Sep 13, 2013 by anonymous
edited Sep 12, 2013
0 votes
This code snippet should help you :) var url = jQuery(this).attr('title'); var shortUrl = url.substring(url.indexOf("-") + 1, url.length); jQuery('#current_url').html(shortUrl);
answered Sep 13, 2013 by anonymous
edited Sep 12, 2013
0 votes
Split the text into an array based on the dash, then get the last item in the array:

console.log($(this).text());
var text = $(this).text().split('-');
$(this).text(text[text.length-1]);

You can trim the spaces in the front as well, if needed.
answered Sep 13, 2013 by anonymous
edited Sep 12, 2013
0 votes
This code snippet should help you :) var url = jQuery(this).attr('title'); var shortUrl = url.substring(url.indexOf("-") + 1, url.length); jQuery('#current_url').html(shortUrl);
answered Sep 13, 2013 by anonymous
edited Sep 12, 2013
0 votes
That's because your replace function doesn't find the desired string, your title is Superlong Sites' Title - and you are trying to replace Superlong Site's Title-.

$(document).ready(function() {
  $('#current_url').text(function(){
     return $('title').text().replace("Superlong Site's Title - ", '');
  })
});
answered Sep 13, 2013 by anonymous
edited Sep 12, 2013
0 votes
Split the text into an array based on the dash, then get the last item in the array:

console.log($(this).text());
var text = $(this).text().split('-');
$(this).text(text[text.length-1]);

You can trim the spaces in the front as well, if needed.
answered Sep 13, 2013 by anonymous
edited Sep 12, 2013

...