Domanda

I have been working on an issue which made me confused. I'm new to java script. I have been trying to add a URL to an anchor href using appendTo and click() function in jquery.

This is my HTML code:

<a id="player"></a>

<a id="play-this-video" class="play-video" href="#" linkdata='href="http://site.com/file.flv"'></a>

and this is the jquery code I am using:

<script>
$("a#play-this-video").click(function() {
    var linkdata = $(this).attr('linkdata');
    $(linkdata).appendTo('a#player');                             
});
</script>

But it doesn't work! Am I right or something is wrong?!

È stato utile?

Soluzione

If you want to set the href attribute of your #player link then use .attr()

$("#play-this-video").click(function() {
    var linkdata = $(this).attr('linkdata');
    $('#player').attr('href',linkdata);                             
});
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top