Having a problem with a very simple jquery script

Discussion in 'jQuery' started by klown, Aug 23, 2010.

  1. #1
    When a user focuses on an input box with id #title-title the div with widgettitle class should be replaced with the text in the input box.

    
    		<script type=\"text/javascript\">
    		$(document).ready(function(){			
    $('#title-title').focus(function() {    
    	$('.widgettitle').replaceWith('<h4 class="widgettitle">'+$("#title-title").text()+'</h4>');			
    });
    }
    </script>
    <html>
    Blah Blah
    
    <input type="text" name="title-title" id="title-title" class="tooltip-editor" value="Title">
    
    Code (markup):
    Doesn't seem to work.
     
    klown, Aug 23, 2010 IP
  2. wab

    wab Member

    Messages:
    57
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    43
    #2
    try
    
    $('.widgettitle').html("<h4 class='widgettitle'>"+$('#title-title').val()+"</h4>");
    
    Code (markup):
     
    wab, Aug 23, 2010 IP
    klown likes this.
  3. klown

    klown Peon

    Messages:
    2,093
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    0
    #3
    That works perfectly, Cheers!
     
    klown, Aug 23, 2010 IP
  4. wab

    wab Member

    Messages:
    57
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    43
    #4
    You're welcome
     
    wab, Aug 23, 2010 IP
  5. omarabid

    omarabid Well-Known Member

    Messages:
    1,509
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    130
    #5
    @klown
    You seem not to know the jQuery functions. try visualjquery.com, use it whenever you are not sure.
    Hope it helps :)
     
    omarabid, Aug 23, 2010 IP