How to remove spaces between words in a link? [closed] - javascript

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
Shortened up:
I need
View in iTunes
to appear as
View in iTunes
Detailed:
So basically what I'm doing is I'm trying to link to the itunes store I'll use this link as an example itunes.com/OfMonstersandMen/MyHeadIsAnAnimal.
This links directly to the item on the iTunes store. I'm using blogger and I'm going to automatically fill the links. The only problem with that is the links will appear as itunes.com/Of Monsters and Men/My Head Is An Animal. So what I need to do is use javascript or jquery to remove the spaces between the words in the link.
I've been looking all over for a solution. Is there anything I can do to fix this??

jsBin demo
$('.view-itunes a[href*=" "]').prop('href', function(i, v){
return v.replace(/%20/g,"");
});
Cause the browsers translates blanks inside href with %20

View in iTunes
<a id="result">View in iTunes</a>
<!--this is a example to result:-->
<b></b><br>
jquery
var aq = $('a').attr('href').split('%20').join('');
$('#result').attr('href',aq);
//this is a example to result:
$('b').text(aq);

Just use string replace function
var a="test%20string";
var b=a.replace(/%20/g, "");

Related

How do I target $0 without getElementById [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
I am trying to find the appropriate way to edit an element but it seems like their is only one node with an ID. I have thought of
my code looks like:
var root=document.getElementById("app-mount").childNodes;;
var child = root[n].innerHTML;
But this is not reusable to get the path to any element such as $0 used in chrome dev tools. I was wondering if there was a method one could call on $0 to just give me the path so one could know how to target it as one does for an ID document.getElementById('id');
Edit:
after getting help I have updated my code to look like:
document.querySelectorAll('svg')[1].outerHTML="<img id='orb' class='orb' src='https://i.imgur.com/k3d8qMN.gif' width='50' height='60'>"
Its for a theme I am making for discord!
Thanks for the help!
I am not sure that I am following your question very well, but if I understand you correctly, you are looking for something like querySelector or querySelectorAll.
You can use CSS commands to target various HTML elements. eg:
document.querySelector('div'); //returns the first div
document.body.querySelectorAll('div'); //returns all the divs attached to the body element
You can also target ids:
document.querySelector('#app-mount');
or classes:
document.querySelector('.blue');
and query selectors may also be used:
document.querySelector('#app-mount > ul > li:nth-child(3)');

Guided Scrolling on web page [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
How does this page accomplish the (guided scrolling?) technique between two divs, where with just a small flick on the scroll pad it takes you to the next element?
http://sourcing.alibaba.com/buyermarket/buyer_market_home.htm?tracelog=alihomelink
If you want a library, I'd suggest fullPage.js. I used it in a recent project and it does the trick without even bother.
There are a number of methods to achieve this. One of them is jQuery Mousewheel.
Here is a simple example of how it works:
$('#my_elem').on('mousewheel', function(event) {
console.log(event.deltaX, event.deltaY, event.deltaFactor);
});
// using the event helper
$('#my_elem').mousewheel(function(event) {
console.log(event.deltaX, event.deltaY, event.deltaFactor);
});
See a working example here: http://jsfiddle.net/DgmWs/5/
Didn't check what library they are using as they are more than likely using a function in jquery or dojo to do this for them but in terms on pure js and dom intereaction. They are doing something like this
window.onscroll = function (oEvent) {
// called when the window is scrolled.
var el = document.getElementById('#someid');//could be selecting the element by class or other means
el.scrollIntoView(true);
}
See the docs for more details:
https://developer.mozilla.org/en-US/docs/Web/API/element.scrollIntoView
https://developer.mozilla.org/en-US/docs/Web/API/window.onscroll

Showing div's by URL [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I know this is probably a stupid question but unfortunately our programmer at work is sick today, of course my deadline is today... I seriously have no clue.
I have 2 divs: .translate_EN and .translate_NL
Well the problem is I need to show .translate_EN when my URL contains /en/ and show .translate_NL when my URL contains /nl/. It can also be selected by: www.domain.com/en/ and www.domain.com/nl/
You will help me ALOT if you can provide me this script!
Many thanks in advance!
This code will return '/en/' if url contains '/en/' or null if it doesn't.
window.location.href.match('/en/')
So you can write if block and make your div's property display block or none.
E.g.:
Make your divs style: display: none then on the page write that code inside <script> tag:
var isEn = window.location.href.match('/en/');
var makeVisible = function(className) {
document.getElementsByClassName(className).item().style.display = 'block';
}
if (isEn)
makeVisible('translate_EN');
else
makeVisible('translate_NL');
I don't know all your requirements but that code will help you to understand what you need to do.
If you have a jQuery on your page, then it can be done with that code:
$('.translate_' + window.location.href.match(/\/[a-z]{2}\//g).pop().replace(/\//g, '').toUpperCase()).show()

How can I remove visible HTML syntax from text in a browser? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 days ago.
Improve this question
We are pulling in the Editorial Review from the Amazon API, and it includes some inline HTML syntax which should not be displayed.
How can we most simply remove extra HTML syntax which is displayed to the viewer? Potentially with some javascript?
You can see an example of this if you look at the review after you click 'View Details' on a bulb on Bulbtrip.com.
Thanks!
Adam
Try using this
var actualString = "<span>Some Text</span> Some other Text <br/> sfahgukasfg <p > ";
removedHTMLTagsString = actualString .replace(/<[^>]+>/ig,"");
alert(removedHTMLTagsString );
To remove the tags themselves you can use a non-greedy regex.
s = s.replace(/\<.*?\>/g, ' ')
will replace all <tags> in a string with a single space.

Saving information in HTML Tags / jQuery [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I want so save states of containers in any tags of them to use it with jQuery. The problem is JS says undefined if I use data-xy and data() or attr().
What is the best way to achieve this?
Had this a lot of times. the data attribute will be lowercase, always.
Say:
<div id="hello" data-testHello="HelloThere">Test</div>
The data will still be accessed by:
$('#hello').data("testhello"); rather than "testHello".
Hope this helps.
Create an object with property as the id of div or element, and the value.
<div id="foo"><span>this is a test</span></div>
For set the state
var stateStore = {};
stateStore["foo"] = "dirty";
For access to the state
$("div").each(function(){
MakeAnythingWithIt(this);
})
function MakeAnythingWithIt(theElement)
{
var elementState = stateSore[$(theElement).attr("id")];
}
Another way is append an input type="hidden" with the state information

Categories