HTML data tag data attribute not updated by jQuery change

As you can see from this JSFiddle: http://jsfiddle.net/cYxy7/1/

I am using jQuery to change the 'data' attribute of an object tag. However, although I can change the data attribute in the source code, the actual data stream of the object does not change and the same video is played. Does anyone know of a fix?

I tried several “upgrade” methods and no one has worked so far.

HTML:

<object data="currentURL"></object>

JQuery

$(document).ready(function(){
    $('body').on('click', "button#switch", function() {
    $( "object" ).attr("data", newURL);
});        
})
+4
source share
6 answers

EDIT:

I found out something else strange. Changing parameters does not work until you change the model of the object window:

$(document).ready(function(){
    $('body').on('click', "button#switch", function() {

    $( 'object param[name="flashvars"]' ).attr("value", "hostname=www.twitch.tv&channel=liquidwifi&auto_play=true&start_volume=25");

     $( "object").attr('data',  "http://www.twitch.tv/widgets/live_embed_player.swf?channel=liquidwifi").hide().show(); 

});        
})

: http://jsfiddle.net/W7NTd/1/


- , html:

$(document).ready(function(){
    $('body').on('click', "button#switch", function() {
        $('object param[name="flashvars"]').attr('value', $('object param[name="flashvars"]').attr('value').replace('ivan', 'liquidwifi'));
        var new_html = $('#wrapper').html();
        $('#wrapper').html(new_html);
    });        
})

.

.

0
0

, :

$( "object param[name=flashvars]" ).attr("value", "hostname=www.twitch.tv&channel=liquidwifi&auto_play=true&start_volume=25");
$( "object").css('display', 'none');
$( "object").attr('data',  "http://www.twitch.tv/widgets/live_embed_player.swf?channel=liquidwifi").css('display', ''); 

. http://jsfiddle.net/W7NTd/2/

0

. .

 $("object param[name=flashvars]").attr("value", $("object").attr("data"));
0

$( "object" ).replaceWith('<object data="' + newURL + '"></object>');
0

,

attr param flashvars

:   http://jsfiddle.net/cYxy7/3/

$(document).ready(function () {
    $('body').on('click', "button#switch", function () {
        alert("The object 'data' attritube is currently: " + $("object").attr("data"));
        $("object").attr("data", "http://www.twitch.tv/widgets/live_embed_player.swf?channel=liquidwifi");
        $("param[name='flashvars']").attr("value", "hostname=www.twitch.tv&channel=liquidwifi&auto_play=true&start_volume=25");
        alert("The object 'data' attribute is now: " + $("object").attr("data"));
    });
})

!

-2

Source: https://habr.com/ru/post/1530584/


All Articles