Search code examples
javascriptjqueryjplayer

How to update jPlayer title?


I'm trying to update the display title of a jPlayer object (encircled in red), after the jPlayer object has already been instantiated with a different audio file.

jPlayer object example

I'm using the following code, which doesn't seem to be working:

$("#jplayer-id").jPlayer("setMedia", {
    title: "NEW TITLE"
});

What am I missing? Thanks.


Solution

  • Try this for setMedia setting the title within the jPlayer ready event:

    $("#jplayer-id").jPlayer({
        ready: function () {
            $(this).jPlayer("setMedia", {
                title: "NEW TITLE",
            });
        },
    });
    

    If already initialized, you can use jQuery to target its jp-title class.

    $("#jplayer-id .jp-title").text("NEW TITLE");