Go Back   CodingForums.com > :: Client side development > JavaScript programming > JavaScript frameworks

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-05-2013, 01:13 PM   PM User | #1
cancer10
Regular Coder

 
Join Date: Jun 2006
Location: India
Posts: 799
Thanks: 211
Thanked 2 Times in 2 Posts
cancer10 can only hope to improve
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
cancer10 is offline   Reply With Quote
Old 02-05-2013, 01:50 PM   PM User | #2
sunfighter
Senior Coder

 
Join Date: Jan 2011
Location: Missouri
Posts: 2,498
Thanks: 18
Thanked 362 Times in 361 Posts
sunfighter is on a distinguished road
Please put the jquery and the div that is causing problems to this thread.
sunfighter is offline   Reply With Quote
Old 02-05-2013, 02:01 PM   PM User | #3
cancer10
Regular Coder

 
Join Date: Jun 2006
Location: India
Posts: 799
Thanks: 211
Thanked 2 Times in 2 Posts
cancer10 can only hope to improve
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>
cancer10 is offline   Reply With Quote
Old 02-05-2013, 04:39 PM   PM User | #4
sunfighter
Senior Coder

 
Join Date: Jan 2011
Location: Missouri
Posts: 2,498
Thanks: 18
Thanked 362 Times in 361 Posts
sunfighter is on a distinguished road
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);
	});
});
sunfighter is offline   Reply With Quote
Users who have thanked sunfighter for this post:
cancer10 (02-06-2013)
Old 02-05-2013, 11:49 PM   PM User | #5
DanInMa
Senior Coder

 
DanInMa's Avatar
 
Join Date: Nov 2010
Location: Salem,Ma
Posts: 1,336
Thanks: 13
Thanked 207 Times in 207 Posts
DanInMa is on a distinguished road
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.
__________________
- Firebug is a web developers best friend! - Learn it, Love it, use it!
- Validate your code! - JQ/JS troubleshooting
- Using jQuery with Other Libraries - Jslint for Jquery/other JS library users
DanInMa is online now   Reply With Quote
Users who have thanked DanInMa for this post:
cancer10 (02-06-2013)
Old 02-06-2013, 01:52 AM   PM User | #6
felgall
Master Coder

 
felgall's Avatar
 
Join Date: Sep 2005
Location: Sydney, Australia
Posts: 5,532
Thanks: 0
Thanked 503 Times in 494 Posts
felgall is a jewel in the roughfelgall is a jewel in the roughfelgall is a jewel in the rough
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/
felgall is offline   Reply With Quote
Users who have thanked felgall for this post:
cancer10 (02-06-2013)
Old 02-06-2013, 03:00 AM   PM User | #7
cancer10
Regular Coder

 
Join Date: Jun 2006
Location: India
Posts: 799
Thanks: 211
Thanked 2 Times in 2 Posts
cancer10 can only hope to improve
thanks guys for your reply.
cancer10 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:38 AM.


Advertisement
Log in to turn off these ads.