0
votes

My idea is to press a button that takes me to a web page. I've created a thing that dynamically creates a button and an anchor tag. When the button is clicked, I want it to "click"/fire up the anchor tag..

I've uploaded a demo to my site, when you try it out just leave everything as it is. Click the first button then the add button right away.. then try to click the dynamically created button.

Nothing happens, but if you watch the source you can find an anchor tag with the ID FL1000, I've set it up so that the anchor tag gets the ID from the value of the created button + 1000 just incase I need to use that ID..

Thanks guys...

edit: this is optimized for google chrome, haven't tried it out with other browser.

edit 2 (solution): Instead of "triggering" the click function on the anchor tag I simply made a variable that takes the href attribute from the anchor tag and goes to that location through document.location.

example:

var disis = $(this).val();
var tislink = '#' + disis + '1000';
var alink = $(tislink).attr('href');
window.open(alink,'_blank');

Thanks guys!

3

3 Answers

2
votes

if your idea is to press a button that takes someone to a web page, what is the reason you need to create links? why not just say in javascript

window.location = "your url";

and you can do this in the same function that creates your link, if you really have to have a link created on the page

And in case you HAVE TO fire a click on the anchor tag, you can do this with jQuery trigger
a nice and simple example at http://api.jquery.com/trigger/

1
votes

You haven't told the new button what to do. For example, try this:

.attr({onclick: 'alert("hello");' type: 'button', 
    class: 'stor blocks red awesome neu', value: vID, id: 'getmylink'});

When you click, you'll get the alert, now just replace it with either `document.location="newpage.html", or what you will.

0
votes

Whats the story with this:

var tislink = '"#' + disis + '1000"';

do you mean

var tislink = '#' + disis + '1000';

?