Javascript Breaking Audio Players
Solution 1:
Looking at your HTML, the result is not surprising: you are scoping the append()
to the element with the class audio
, and that is the <article>
. jQuery appends your new div
to the end of that scope – which is the bottom of the article. You need to change the scope of your element insertion, either by
Iterating over elements of class
audio-player
instead ofaudio
, i.e.$('.audio-player').each(function(){ … }
As this changes the scope of
this
, you will also have to adjust the line retrieving the post ID to look up the element hierarchy, i.e.var audioID = $(this).parents('.audio').attr('id');
or by
Scoping your element insertion to the player element proper, i.e.
$audioPost.find('.audio-player').append('<div style=\"background-color:black;">' + data.posts[0]['audio-player'] +'</div>');
If you’d rather replace the
span
inside that element instead of appending to it, so your player replaces the Flash warning, do$audioPost.find('#audio_player_'+audioID).replaceWith('<div style=\"background-color:black;">' + data.posts[0]['audio-player'] +'</div>');
instead.
Answer edited after some trial and error on-site testing via chat; please ignore the comment thread.
Post a Comment for "Javascript Breaking Audio Players"