-1

I am trying to replace spaces in hyperlink text with hyphen(-).
Below is my anchor tag :

<a href="${user.workstation}"></a> 

and I want some something like this :

<a href="replace(${user.workstation}, " ", "-")"></a> 

Please advice.

YoungHobbit
  • 13,254
  • 9
  • 50
  • 73
kamal
  • 77
  • 9
  • 1
    javascript has simple function called `.replace` https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace cant you use that ? – Bek Dec 29 '15 at 05:43
  • 1
    Try, str.replace, http://www.w3schools.com/jsref/jsref_replace.asp – Ravneet Dec 29 '15 at 05:44
  • use this link -----> http://jsbin.com/zimimozetu/edit?html,js,output – Pankaj Bisht Dec 29 '15 at 05:51
  • Thanks @Bek, I will try this. – kamal Dec 29 '15 at 05:57
  • Possible duplicate of [Replacing spaces with underscores in JavaScript?](http://stackoverflow.com/questions/441018/replacing-spaces-with-underscores-in-javascript) – Shiv Singh Dec 29 '15 at 06:01
  • @ShivSingh : It's not. In my case I wanted as inline as I mentioned above in my example code. – kamal Dec 31 '15 at 14:30

1 Answers1

1

Please try this

var corrected = $('a').attr('href').replace(/ /g,'-');
$('a').attr('href' , corrected );

The replace() method searches a string for a specified value, or a regular expression, and returns a new string where the specified values are replaced.

g Perform a global match (find all matches rather than stopping after the first match)

Rino Raj
  • 6,264
  • 2
  • 27
  • 42
  • Is it possible to use this kind of code as inline as I have mentioned in above example ? – kamal Dec 31 '15 at 14:17