views:

43

answers:

2

How would I change the html of a tag like so:

$('#someId').html('<p>foo bar</p>');

while using the live() or delegate() function? Just for clarification I don't want this to happen on hover or focus or click... I just want jquery to immediately change the html inside of a certain tag.

Basically, I'm trying to change the logo in the Mojomotor's little dropdown panel and I don't want to change the logo every time I upgrade to a new version.

Any suggestions?

+3  A: 

.live() and .delegate() don't work like this, what you're after is still done through the .livequery() plugin or simply in the document.ready if it's present on page load, like this:

$(function() {
  $('#someId').html('<p>foo bar</p>');
});

Or with .livequery() if it's replaced dynamically in the page:

$('#someId').livequery(function() {
  $(this).html('<p>foo bar</p>');
});

.live() and .delegate() work off of event bubbling...an element just appearing doesn't do this whereas a click or change, etc would.

Nick Craver
Thanks. I tried doing it on document ready with no results so I'll try the livequery plugin you suggested.
Johnny Freeman
+1  A: 

Just do it when the DOM loads.

<script type="text/javascript">
    $(document).ready(function() {
        $('#someId').html('<p>foo bar</p>'); 
    });
</script>
Randall Kwiatkowski
I tried this and It didn't work.
Johnny Freeman
Make sure you have included the jquery library and be sure to put the ready function between script tags. Also post the HTML of #someId and we might be able to see why.
Randall Kwiatkowski