JavaScript Creating a link tag with parameters creating link with hyperlink,creating link in html,creating link

Hi i have a link tag that i am creating from javascript. now i want to append a parameters to that link just like below example.so that when the user clicks that button it should go to that url along with the paramenters

var id="123456789";
var data = '<a target='_blank' href="/order/product/ + id"> click</a>' ;

this data tag i am appending to some other element. now i can able to call /order/product. but when i give id also it is giving error "missing arguments"!! can anyone please help me?

Answer:1

You'll have to unquote the string where the variable goes

var id   = "123456789";
var data = '<a target='_blank' href="/order/product/' + id + '"> click</a>' ;

Or on really up-to-date JavaScript engines that support ES2015+ template literals:

var id   = "123456789";
var data = `<a target='_blank' href="/order/product/${id}"> click</a>`;

But that won't work on any version of IE (does on Edge).

Answer:2

For easy create link you can use method link(str) of String:

var id="123456789";
var linkText = " click";
var href = "/order/product/" + id;
var data = linkText.link(href);
alert(data);
Answer:3

To make it easier both to write and read (and debug too), I'd recommend the following variant of how to organize the code:

var id = "1234566",
    // It is more understandable now that hrefLink contains id concatenated with some other string
    hrefLink = "/order/product/" + id,
    link = document.createElemen('a');
link.href = hrefLink;

In this way you

  1. See what variable means what
  2. Control what your hrefLink consists of
  3. Follow best practises when instead of multiple lines with var statement you explicitly "show" where the declaration section is:

    var a = smth1,
        b = smth2;
    

So just by looking at this code you easier understand that that is a code chunk of variables declaration

Answer:4

I want to know if there is any benefit in passing off db or other async calls to a worker process or processes. Specifically I'm using heroku and postgres. I've read up a good bit on node.js and how ...

I want to know if there is any benefit in passing off db or other async calls to a worker process or processes. Specifically I'm using heroku and postgres. I've read up a good bit on node.js and how ...

  1. using background worker
  2. using backgroundworker c#
  3. use backgroundworker class
  4. using background worker in vb.net

I am making a website in Socket.io. But emit method not working in my code. I can't see any errors in my code. Here is my server code. var io = require("socket.io").listen(server); //Some external ...

I am making a website in Socket.io. But emit method not working in my code. I can't see any errors in my code. Here is my server code. var io = require("socket.io").listen(server); //Some external ...

  1. node socket emit
  2. node js socket emit
  3. node js socket emit example
  4. node socket.io emit
  5. node.js socket.emit callback
  6. node js socket emit error
  7. node js net socket emit
  8. node.js socket.io emit
  9. node.js socket.io emit json
  10. node js socket io emit callback
  11. node.js socket.broadcast.emit
  12. socket.emit node.js not working
  13. node.js socket.volatile.emit

I'm trying to play a video that I've CENC-encrypted using MP4box with these options: MP4Box -crypt drm_file_gpac_clear.xml BigBuckBunny.mp4 -out BigBuckBunny_cenc.mp4 Where the XML file specifies ...

I'm trying to play a video that I've CENC-encrypted using MP4box with these options: MP4Box -crypt drm_file_gpac_clear.xml BigBuckBunny.mp4 -out BigBuckBunny_cenc.mp4 Where the XML file specifies ...

I am using axios for AJAX in Vue. In the article written by You, he mentioned that we can set Vue.prototype.$http = axios and I can use this.$http in Vue instance. It works fine. However, if I want ...

I am using axios for AJAX in Vue. In the article written by You, he mentioned that we can set Vue.prototype.$http = axios and I can use this.$http in Vue instance. It works fine. However, if I want ...

  1. create instance axios
  2. create axios instance react
  3. create axios instance vue