I send {{name}} to my url.
<a href="#/{{_id}}/{{name}}/apps_details" class="app-anchor" data-appname="{{name}}" data-appid="{{_id}}"data-filtercriteria="{{filtercriteria}}">
URL='/:id/:name/apps_details'
But in here if name=test one then url not go to desire page. I think space between "test" and "one" cause to this. so how to remove this spaces in {{name}} parameter.
I want to remove spaces in {{name}} not some string value..replace(/\s+/, "") cannot use to do that
Related
i am trying to append 4-5 apces by the below code but it's not
working. new to Jquery,JS pls help.
$("#<%= lbl100.ClientID %>").text("Your search request is too broad and the first 100 results are displayed.Please refine your search if your result does not show.").append(" ");
Note:- I have also used   and adding space in the end(not worked) but they are printing as it is and space not coming
Use with html()and make sure that id:- <%= lbl100.ClientID %> is correct and exists.
Example:-
$("#abc").html("Your search request is too broad and the first 100 results are displayed.Please refine your search if your result does not show. ").append(" ");
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="abc"></div>
Note:- if you try to select the text then you will see that spaces are also selected.
Another way to do it:-
$("#abc").html("Your search request is too broad and the first 100 results are displayed.Please refine your search if your result does not show. see the space");
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="abc"></div>
Note:- Make sure that jQuery library added before your script code otherwise it will not work and you will get $ is undefined error in your browser console.
That's how HTML works: white-space is collapsed into a single space. If you need hard-coded duplicate spaces you need to insert a literal U+00A0 NO-BREAK SPACE character. There're several ways to do it:
Type it as-is (you may also use the clipboard)
Insert a JavaScript entity
Insert an HTML entity
Snippet illustrates #2 and #3 (the editor would convert the character to regular space):
$("div:nth-of-type(1)").text("One\u00A0\u00A0\u00A0\u00A0Two");
$("div:nth-of-type(2)").html("One Two");
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div></div>
<div></div>
I have a big string: Hello <span class="ashakd">my</span> name is <bob>!
I have a second string: llo my name
I have what i want to replace it with:<span class="ashakd">llo my name</span>
I need to replace() it as if the <span class="ashakd"> and </span> didnt exist, but they are replaced with the string so the final result is: He<span class="ashakd">llo my name</span> is <bob>!
PS: <bob> exists so you cant ignore any text between two >'s it must specifically ignore <span class="ashakd"> and </span>
very sorry if this is confusing. ask me to make it clearer if this is confusing
edit
sorry for being unclear, but it must only replace the within my replace. so if the original string was: Hello <span class="ashakd">my</span> name is <bob><span class="ashakd">hello</span>!
the result would be: He<span class="ashakd">llo my name</span> is <bob><span class="ashakd">hello</span>!
This may be too destructive to the original string, but I propose this solution:
var a = 'Hello <span class="ashakd">my</span> name is <bob>!';
var searchString = 'llo my name';
// remove all <span> and </span> tags, you may not want to remove any and all span tags???
a = a.replace(/<\/?span[^>]*?>/g,'');
a = a.replace(searchString,"<span class='ashakd'>"+searchString+"</span>");
What this does is remove all span tags, then search for your "llo my name" search string, and wrap that with a span tag.
Since you said you don't know regex that well, here's a description of:
/<\/?span[^>]*?>/g
<\/? means match on '<' and then optionally a /. This matches both the start and end tags, i.e. <span...> and </span>
[^>]*? means match any character that is NOT > in a non-greedy fashion, i.e. stop matching at the first > found.
The final /g means 'global', which means match <span> and </span> as many times as possible.
I have the following:
<g:each status="i" var="grade" in="${chooseList}">
<div id="grade_${grade}" class="dojoDndItem" dndType="avail">
<g:remoteLink action="getMappings" controller="dataManagement" update="mappedSkills" params="[grade:grade.toString()]" id="1">${grade}</g:remoteLink>
</div>
</g:each>
When I print out params.grade in my controller, it "looks+like+this"
in other words, the spaces are replaced with "+"
what causes that? Can I get rid of it, or do I have to take care of it from within my controller?
It appears that your values are coming in from params as URL Encoded. Try params.grade.decodeURL() in your controller to remove the pluses.
I use Javascript
I have this:
<(div|span) class="search-result-(body-text|title)">(.*?)</(span|div)>
And i use is on this content:
<div class="search-result-item club">
<span class="search-result-type">Projekt</span
<span class="search-result-title">Titel</span>
<div class="search-result-body-text">
Body text
</div>
<div class="search-result-attributes">
<span class="search-result-attribute">Attribute</span>
</div>
</div>
My result is:
<span class="search-result-title">Titel</span>,
<div class="search-result-body-text">
Body text
</div>
Thats make sense, but how should my regexp look like so it strips the tags, so i only get: Titel, Body text
It is required by law that someone post a link to this: RegEx match open tags except XHTML self-contained tags which you should read and reconsider whether you really want to be parsing HTML using regular expressions.
However, what you want is the contents of the third () group in your match. The exec method of a JS regular expression object is an array containing the whole match at index 0, and the matches from all the groups at indices 1,2,... (in this case index 3 is what you need).
[NOTE: an earlier version of this answer had "first" and "1" instead of "third" and "3" above, because I misread your regexp. Sorry.]
I have a page that I am trying to dynamically add some links to. The links are getting added to the page fine, but the '[' and ']' at either end of the line are getting dropped. The code from my .js file is:
var html = "[ <a href='#'>Change</a> | <a href='#'>Remove </a> ]";
$(html).appendTo("#id123");
The result I want is:
[ <a href='#'>Change</a> | <a href='#'>Remove</a> ]
The result I'm getting is:
<a href='#'>Change</a> | <a href='#'>Remove</a>
If I wrap the line in a <span> tag like so:
var html = "<span>[ <a href='#'>Change</a> | <a href='#'>Remove </a> ]</span>";
$(html).appendTo("#id123");
it renders as expected. I set a breakpoint on the code and checked the html var right before the .appendTo and it contains the '[' and ']'.
Anyone know why this is happening? Are '[' and ']' special character that need escaped and I'm just forgetting that fact?
When you wrap your html variable inside of "$()", it creates a jQuery object out of it. That object removes anything that's outside of a markup tag (like <a> or <span>). You can take out the"[" and put "TESTING THIS" in it's place and you'll see it still won't show up.
So that's why you're losing it in your output.
No, those are just not valid XHTML. If you put the '[' and ']' in their own spans, like so:
"<span>[ </span><a href='#'>Change</a> | <a href='#'>Remove </a></span> ]</span>"
You would also get your expected text. jQuery will parse and create valid HTML, and the brackets aren't contained in an element.
I'm not sure why this happens. It seems like something internal to the appendTo() I tried it with append() and it worked out fine. So you could write $("#id123").append(html)