Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Regular Coder
    Join Date
    Jun 2006
    Location
    UK
    Posts
    922
    Thanks
    302
    Thanked 3 Times in 3 Posts

    Question jQuery - Bug in .html() method?

    HI

    Please take a look at the source here... http://jsbin.com/edozum/2/edit

    Can someone please tell me why is the jquery .html() method is adding tbody tag when getting the html from the DIV?

    https://www.dropbox.com/s/j0lw65bmt2wb9zs/code_31.png

  • #2
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,721
    Thanks
    25
    Thanked 662 Times in 661 Posts
    Please put the jquery and the div that is causing problems to this thread.

  • #3
    Regular Coder
    Join Date
    Jun 2006
    Location
    UK
    Posts
    922
    Thanks
    302
    Thanked 3 Times in 3 Posts
    jQuery:

    Code:
    $(document).ready(function(){
    
      $('#btn').click(function(){
      
          var x = $('#test').html();
        $("#ta").val(x);
      
      
      });
      
    
    });


    DIV:
    Code:
    <div id="test">
        
        <html>
    <head>
    	<meta content="text/html; charset=iso-8859-1" http-equiv="Content-Type">  
    	<title>Bienvenue sur Les Chipoteuses</title>
    	                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         																																																																																																																																																																																																					 
    </head>
    <body>
    	<div style="background-color:#F0F0F0;">
    	
    							<table border="0" width="560" cellpadding="0" cellspacing="0" align="center">
    								<tr>
    									<td width="25" height="50"></td>
    									<td width="120" height="50">
    										<a href="#" style="text-decoration:none;" target="_blank"><font size="1" style="font-family:Arial,Sans-Serif; font-size:14px; color:#ED1E79; font-weight:bold;">Version en ligne</font></a>
    									</td>
    									<td width="310" height="50"></td>
    									<td width="80" height="50" align="right">
    										<font size="1" style="font-family:Arial,Sans-Serif; font-size:14px; color:#ED1E79; font-weight:bold; text-align:right;">07.01.2013</font>
    									</td>
    									<td width="25" height="50"></td>
    								</tr>
    							</table>
    						
    			</body>
    </html>
    	
    							
        
        
      </div>

  • #4
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,721
    Thanks
    25
    Thanked 662 Times in 661 Posts
    Your jquery does not deal with anything in that div. The div has no id or class to be dealt with separate from any other div on the page. I think this is not the right div.

    Maybe you want this:
    Code:
    $(document).ready(function(){
    	$('#btn').click(function(){
    		var x = $('#test').html();
    		$("#ta").html(x);
    	});
    });

  • Users who have thanked sunfighter for this post:

    phantom007 (02-06-2013)

  • #5
    Senior Coder DanInMa's Avatar
    Join Date
    Nov 2010
    Location
    Salem,Ma
    Posts
    1,577
    Thanks
    13
    Thanked 248 Times in 248 Posts
    Quote Originally Posted by cancer10 View Post
    HI

    Please take a look at the source here... http://jsbin.com/edozum/2/edit

    Can someone please tell me why is the jquery .html() method is adding tbody tag when getting the html from the DIV?

    https://www.dropbox.com/s/j0lw65bmt2wb9zs/code_31.png
    it's not working correctly becuase your html is way off. youve got the html for an entire html docuiment inside of a div, your confusing your script. \

    ( it's actually doing what you are telling it to do based on you r html in the jsbin example)

    - side note, you are using the html5 doc type, but you are using tags like FONT that were deprecated years ago.

  • Users who have thanked DanInMa for this post:

    phantom007 (02-06-2013)

  • #6
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,642
    Thanks
    0
    Thanked 649 Times in 639 Posts
    All tables in HTML have at least one <tbody> container in them whether you specify the tag or not. When JavaScript accesses the table it sees the tbody and any other optional tags that you left out that HTML added in for you.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • Users who have thanked felgall for this post:

    phantom007 (02-06-2013)

  • #7
    Regular Coder
    Join Date
    Jun 2006
    Location
    UK
    Posts
    922
    Thanks
    302
    Thanked 3 Times in 3 Posts
    thanks guys for your reply.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •