Reputation: 1048
I need to append a hash #play
to the src
attribute on an iframe element once a link is clicked.
Here is what I have attempted so far:
$(".portfolio-link").click(function() {
$('.first').append(.attr('src', '#play'));
});
Here is the link that I want to add #play
to the src
attribute on click: <a href="#portfolioModal1" class="portfolio-link" data-toggle="modal"></a>
Here is the iframe element: <iframe class="first" src="http://my.iframe.url" width="160" height="600" frameborder="0"></iframe>
How can I accomplish this with jQuery?
Upvotes: 1
Views: 3002
Reputation: 1458
var currentSrc = $('iframe.first').attr('src');
$('iframe.first').attr('src', currentSrc + '#play');
Upvotes: 1
Reputation: 3761
You could do a couple of ways. first, you could save the src as a variable and use that:
var myUrl = $('.first').attr('src');
$('.first').attr('src', myUrl + "#play");
or you could do it all in a single step:
$('.first').attr('src', $('.first').attr('src')+"#play" );
Either should work.
Upvotes: 1