applescript with javascript -> get string from href - javascript

I try to read out the string inside of an unordered list .
The string of interest is the following number: href="?notation=1549220"
image
I am very new to HTML/CSS/JavaScript so please excuse this simple question.
I tried something like this, but it's getting nowhere:
document.getElementById('exchangesLayerHs')
.getElementsByTagName('ul')
.getElementsByTagName('li')
.getElementsByTagName('a');
Has anyone a tipp for me?
Thanks a lot!
Carlo

You could get the link with the title handelsplatz geschlossen :
var link = document.querySelector("a [title='Handelsplatz geschlossen']");
Now simply get the thing behind = in the href and convert it to a number (+) :
var result = + link.href.split("=")[1];

Related

Hi Folks, I want to remove text written inside [ ] and need to replace with blank. Can someone hep me on this?

Example:
The code is [cid:7108371312034834373] used to create your new account.
and need to change the string to
The code is used to create your new account.
Thanks in advance.
You can use regex here /\[.*?\]\s*/ and replace to achieve the result
const str =
"The code is [cid:7108371312034834373] used to create your new account.";
const result = str.replace(/\[.*?\]\s*/, "");
console.log(result);

R string replacing part of javascript

I'm sure this is a noob question but I couldn't figure out how you would insert a R string object inside a javascript. For example,
trackname <- "audiotrack1"
into
tag$script(var url = 'audioResources/' + trackname + '.wav')
Where I would want to replace the "trackname" with "audiotrack1". I'm sure paste0 isn't the best way to do this. What is the standard way to go about doing this?
Many thanks.
This is not correct. You can do:
tags$script(HTML(sprintf("var url = 'audioResources/%s.wav'", trackname)))
An option with glue
library(glue)
tags$script(HTML(glue::glue("var url = 'audioResources/{trackname}.wav'")))

Joining two text values to form hyperlink

I'm prefacing this with the fact that coding is most definitely not my strong suit.
I'm currently trying to join two pieces of text to form a link sitting behind an image. The first piece of text is defined (https://www.example.mystore.com/customers/) with the second part being from a datatable (<span id="customcontent752">[Link ID]</span>). Question is - how do I get both of these pieces of information to join to form
https://www.example.mystore.com/customers/[Link ID]? I figure it's something simple I can drop into the source code, but can't for the life of me work it out.
Cheers in advance!
var firstPiece = "https://www.example.mystore.com/customers/";
var secondPiece = $("#customcontent752").text().trim();
var result = firstPiece + secondPiece; //"https://www.example.mystore.com/customers/[Link ID]"
Simply use the + operator if both are strings.
i.e
"https://www.example.mystore.com/customers/" + link_id
should get you what you want.
you can use concat :
var x = "https://www.example.mystore.com/customers/"
var y ="[link ID]"
var result = x.concat(y)

converting JS variable to string & display it in html

Im newbie in JS so please bear with me.
I have a JS variable that i got from web service (JSON type). I tried to alert this variable and its working, returning 1 (integer) :
alert(result[0].totalMall);
I want to add a string to this variable so it will become like (for example) : 1 mall(s)
This is my code :
var result = result[0].totalMall.toString() + "Mall(s)";
alert(result);
$('.totalMall', this).html(result);
But the alert above always returning undefined. What should i do? I have been working for hours to just fix this.
And the result always displaying just "mall(s)" without the integer (result[0].totalMall.toString()) with it.
Any help is appreciated. Thanks :D
try following code:
var results = [
{
totalMall :3
},
{
totalMall :5
}
];
var result = results[0].totalMall.toString() + " Mall(s)";
alert(result);
$("#div").html(result);
Working example: http://jsfiddle.net/WaydY/
Thanks for your help, all :D
yes, it appears that "something" was wrong last night. I tried the code this morning, and its working fine now :D

javascript string replace with another value

Hello there ,
var s = "width:20px;height:25px;color:red;font-family:myfontfamily";
i have a string like this,now how can i change the values of width,height etc using javascript.there may be a \n after or before the properties (width,height etc)..
Ex : i want to change width to 50px on s.
so it will be
var s = "width:50px;height:25px;color:red;font-family:myfontfamily";
My another replated Question is here Regular Expression to get text from css but it not working exactly what i need.
Please help me.
Thank you.
Update : You can see the Result on my fiddle here : http://jsfiddle.net/jitheshkt/s2DJR/14/
Regular expressions.
For example:
s = s.replace(/color:\s*([^;]+)/, "color:" + newvalue)
var s = "width:20px;\nheight:25px;\ncolor:red;\nfont-family:myfontfamily";
alert( s.replace(/width:\d+/,'width:123').replace(/height:\d+/,'height:456') );

Categories

Resources