Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Modifying innerHTML from 3rd Party Script

I have a 3rd party script that is importing a menu and I cannot edit this 3rd party script. It generates code like this:

<div id="wmenu-updated" style="display: block;">
  <small>Menu updated</small>
  <span innerhtml="19 hours ago"></span>
</div>

It should take 19 hours ago and display that as text inside the span but for whatever reason it doesn't work and the makers of the script are little help in fixing the error.

Is there a way, using jQuery, that once the page loads I can take the innerhtml and spit it out as text inside that span?

like image 226
L84 Avatar asked Feb 11 '13 04:02

L84


2 Answers

$( document ).ready( function () {
    $( '#wmenu-updated span' ).text( function () {
        return $( this ).attr( 'innerhtml' );
    });
});

You can use jQuery's text function to update the text in the span

like image 150
whitneyit Avatar answered Sep 20 '22 18:09

whitneyit


Use $.attr() and $.text() to achieve this

$(document).ready(function(){
   var txt = $("#wmenu-updated span").attr("innerhtml");
   $("#wmenu-updated span").text(txt);
});
like image 32
Hary Avatar answered Sep 20 '22 18:09

Hary