0

I am building a questionnaire in mostly javascript. Each question is added to the page with JS after the next button is clicked and on page load.

In IE if I view source it does not actual show the question that was added by JS. The question is added, and that part works fine.

Now, I am doing:

f.parent().parent().attr("class").split(" ")[1]

to get a class from a question. This works in IE8 and all other browsers but not IE9.

If I do:

f.parent().parent().hasClass("foo")

it returns false! But it does have the class, although I cannot see any of the html of the question added with JS, and I assume that IE does not see it!!

This both works in IE8...

IF i console.log a object it justs gives me a text : LOG: [object Object]. that does not help either, because you cant even click the object as in all other debuggers!!! IE....

EDIT:

After more testing:

You click a button to call this class() part. If I do: console.log($(f.parent().parent()).text()) it returns the buttons text! so the .parent().parent() does not actually work right

HTML

<tr class="matrix_row other>
<td>Other (specify)</td>
<td>&nbsp;</td>
<td>
<a class="add_more_matrix_input" href="#">Add one</a>
</td>
</tr>

Javascript:

$(".add_more_matrix_input").live("click", function() {
            var f = $(this);
            // console.log($(f.parent().parent()).text())
            last_key = f.parent().parent().attr("class").split(" ")[1]
7
  • Don't forget that the view source will not show you the updated DOM, to see the DOM after the html has been manipulated by JavaScript, you need to use the IE developer tools. Commented Sep 5, 2011 at 9:12
  • could you post the html code? what is f, what are its parents, what classes are there etc? Commented Sep 5, 2011 at 9:14
  • f = $(this); and that is inside $("#add_more a).live("click", function() {f = $(this);}. Its parent.parent = the row the question is in in a table. so its <tr class="matrix_row other"> Commented Sep 5, 2011 at 9:19
  • So I just need that rows class()[1] that is "other" Commented Sep 5, 2011 at 9:19
  • @Swaf, I am using the dev tools. they suck Commented Sep 5, 2011 at 9:30

1 Answer 1

1

You'd better use f.parents('tr') to reach your tr. Not sure what IE9 could do to make f.parent().parent() not your tr, but it definitely did something bad :).

Anyway, using f.parents('tr') will protect you from side-effects of, say, covering your a with div, which may be needed one day in the future.

Let us know if it still does not work, then we'll try to dig deeper.

Additionally, you should use hasClass. If for some reason it does not work, find that reason, not try to analyze the class attribute.

UPDATE

Additionally, you have missed a closing " in class declaration in tr: <tr class="matrix_row other>

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

3 Comments

So in my case you mean f.parent().parent('tr').attr("class").split(" ")[1] ?
I would use hasClass, but it returns false. Your solutions did not work, Im wondering if there is a syntax error in my html somewhere. im checking now
class="matrix_row other has no closing "

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.