0

I have the following code

HTML

<span id = 'testlabel'></span>

JS

var test = '<tr style="display:none" class="projinfo">test<br/>test</tr>' +   
'<tr><td column="Type"><b>Project</b></td><tr>';

 var dom = $(test).filter('.projinfo');

 var content = dom.length > 0 ? dom[0].innerHTML:'No data';

$('#testlabel').text('Content is ' + content);

jsfiddle

In Chrome, I am expecting the result of my jsfiddle to be

"Content is test
test"

instead I get

Content is

What am I missing here ?

In IE 9 I am getting the correct result ..

1 Answer 1

2

It looks like the HTML jQuery is creating isn't being evaluated the same on Chrome (taking your word that it works in IE). This is because the <tr> doesn't have a <td> inside it. If you change your content to the following:

var test = '<tr style="display:none" class="projinfo"><td>test</td></tr>' +   
'<tr><td column="Type"><b>Project</b></td><tr>';

 var dom = $(test).filter('.projinfo').find('td');

 var content = dom.length > 0 ? dom[0].innerHTML:'No data';

$('#testlabel').text('Content is ' + content);

It'll work properly:

Content is test

jsfiddle

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.