4 Replies - 1420 Views - Last Post: 02 August 2011 - 08:02 AM

#1 fallenreaper   User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 240
  • Joined: 19-June 10

removing whitespace of a href tag on client side on form load.

Posted 02 August 2011 - 06:22 AM

What i was wanting to do is something along the lines of make it so the page loads, and afterwards, manipulate everything with a specific call called "RunGrw"... im trying to remove the white space put in either by spaces or $nbsp..... >_>

I cant change the server side inputs....

this is what i was thinking but isnt working
$(function(){
 $('a.RunGrw').attr('href', $(this).attr('href').replace(" ",""));
 $('a.RunGrw').attr('href', $(this).attr('href').replace("&nbsp",""));
});



Originally i was trying to do it on click that was not fruitful. I didnt know how to embed another function in there, as attr wouldnt make sense. if i could embed, i would do something like
function(){
var contents = $(this).attr('href');
contents = contents.replace(" ","");
contents = contents.replace("&nbsp","");
$(this).attr('href',contents);
}



what would i do to get rid of all the whitespace in the hyperlinks. Essentially it is because things which were processed server side spit out into the request space such as "=size= &lossamt= "

Is This A Good Question/Topic? 0
  • +

Replies To: removing whitespace of a href tag on client side on form load.

#2 Jstall   User is offline

  • Lurker
  • member icon

Reputation: 434
  • View blog
  • Posts: 1,042
  • Joined: 08-March 09

Re: removing whitespace of a href tag on client side on form load.

Posted 02 August 2011 - 06:54 AM

Hi,

You can use $.each() to iterate through your links. .replace() only replaces the first occurrence of a character in a string so you need to use a regular expression with the global flag to replace all occurrences.

Modification of your code:
$('a.RunGrw').each(function(){
  var contents = $(this).attr('href');
  contents = contents.replace(/ /g,"");
  contents = contents.replace(/&nbsp/g,"");
  $(this).attr('href',contents);
})



Something like that would do it.
Was This Post Helpful? 1
  • +
  • -

#3 fallenreaper   User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 240
  • Joined: 19-June 10

Re: removing whitespace of a href tag on client side on form load.

Posted 02 August 2011 - 07:19 AM

will that do it after the form loads entirely? As of right now, the code is in the header, but it isnt changing any of the href elements. I wasnt sure if / / represented whitespace... as i was thinking something else may have to go in there, as per the style of RegEx's

sidenote:

Quote

$('a.RunGrw').each(function(){
var contents = $(this).attr('href');
contents = contents.replace(/ /g,"");
contents = contents.replace(/&nbsp/g,"");
$(this).attr('href',contents);
}); //<--- needed a semicolon.

This post has been edited by fallenreaper: 02 August 2011 - 07:22 AM

Was This Post Helpful? 0
  • +
  • -

#4 fallenreaper   User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 240
  • Joined: 19-June 10

Re: removing whitespace of a href tag on client side on form load.

Posted 02 August 2011 - 07:50 AM

for people who want to know, following standard whitespace delimiters in REGEX formats.... \s is for a single whitespace.

To solve this, the jquery Operation is:

$(function(){
$('a.RunGrw').each(function(){
var contents = $(this).attr('href');
contents = contents.replace(/\s/g,"");
contents = contents.replace(/\u00a0/g,'');  //<-- Regex changed from /&nbsp/g to that.
$(this).attr('href',contents);
});
});


Props go to JStall and Myself. GO TEAMWORK! :)

This post has been edited by fallenreaper: 02 August 2011 - 09:45 AM

Was This Post Helpful? 1
  • +
  • -

#5 fallenreaper   User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 240
  • Joined: 19-June 10

Re: removing whitespace of a href tag on client side on form load.

Posted 02 August 2011 - 08:02 AM

works in all browsers except EXPLORER..... of course. >_> Now i need to find out hwo to make it explorer compatible. Thoughts?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1