O
O. O.
Hi,
I am new to JavaScript – but I have experience with strongly typed
object oriented languages like C# and Java. I don’t know any CSS, and
have never used a prototype based language. I don’t have much
experience with the DOM, but I can understand the basic idea.
I have a HTML table, with one column having a button in each row. The
OnClick event of the/each button is liked to a function like: (This
uses JQuery).
function deleteRow() {
$(this).parent().parent().remove();
}
I copied this from a website, and it did not work for me. So I
attempted debugging this. I think my mistake is in the number
of .parent() calls. For this I needed to figure out where each of the
objects are in the DOM. I modified my original function to look like:
function deleteRow() {
var $t = $(this);
alert($t);
var $t1 = $(this).parent();
alert($t1);
$(this).parent().parent().remove();
}
I was hoping that the above code would show me the type of object of $
(this) and $(this).parent() and from that I would have some idea of
where I am in the DOM. (This would certainly work in C# or Java).
The above code resulted in both of the alert boxes having [object
Object] – which is useless to me. I then used FireBug to step through
the modified function above, and I see $t and $t1 as [Window
temp.html] (where temp.html is the name of my HTML file.) This does
not tell me anything. I tried expanding the hierarchy of $t and $t1 in
the Watch Window of FireBug, and I could not make any sense of the
information.
I understand that this is related to JQuery – but since this is a lot
more basic, I am hoping that someone here can help me. I would like to
know how to figure out where you are in the DOM using a given object
in JavaScript.
Thanks a lot,
O. O.
I am new to JavaScript – but I have experience with strongly typed
object oriented languages like C# and Java. I don’t know any CSS, and
have never used a prototype based language. I don’t have much
experience with the DOM, but I can understand the basic idea.
I have a HTML table, with one column having a button in each row. The
OnClick event of the/each button is liked to a function like: (This
uses JQuery).
function deleteRow() {
$(this).parent().parent().remove();
}
I copied this from a website, and it did not work for me. So I
attempted debugging this. I think my mistake is in the number
of .parent() calls. For this I needed to figure out where each of the
objects are in the DOM. I modified my original function to look like:
function deleteRow() {
var $t = $(this);
alert($t);
var $t1 = $(this).parent();
alert($t1);
$(this).parent().parent().remove();
}
I was hoping that the above code would show me the type of object of $
(this) and $(this).parent() and from that I would have some idea of
where I am in the DOM. (This would certainly work in C# or Java).
The above code resulted in both of the alert boxes having [object
Object] – which is useless to me. I then used FireBug to step through
the modified function above, and I see $t and $t1 as [Window
temp.html] (where temp.html is the name of my HTML file.) This does
not tell me anything. I tried expanding the hierarchy of $t and $t1 in
the Watch Window of FireBug, and I could not make any sense of the
information.
I understand that this is related to JQuery – but since this is a lot
more basic, I am hoping that someone here can help me. I would like to
know how to figure out where you are in the DOM using a given object
in JavaScript.
Thanks a lot,
O. O.