jQuery siblings() function is not working

Hi there

This is my JS file

I am trying to get text of studentId class but that is not working as you can see in my above function using siblings() function of JQuery

How can I do this?
Whats wrong with my JS fiddle?

Thanks

By logging the this keyword, we can see what the problem may be.

function changeStudentStatus() {
    console.log(this);

What we see when this function is triggered is that the this keyword refers to the window. That’s not what you want.
What you want is for the this keyword to refer to the link that was clicked.

First, we need to move the inline javascript code out of the HTML and in to the JavaScript, so that it will work properly for you.

The account status link returns back to something sensible:

<a href="#" class="accountStatus">Account Here</a>

And we can tell jQuery to watch for any clicks on accountStatus in the studentList, and run that function.

Because you are using jQuery 1.6.4, we’ll use the older delegate technique.

$('.studentList').delegate('.accountStatus', 'click', changeStudentStatus);

If you are using jQuery 1.7 or better, you can use the superior and more consistent .on() method.

$('.studentList').on('click', '.accountStatus', changeStudentStatus);

Now clicks on an Active link appropriately trigger the function, with the this keyword pointing to the link itself.

You still have more work to do from there because you are starting from deep down inside of a td element, but you will be closer to a solution after following the above advice.

@Paul_Wilkins

Thanks this is pointing to right direction know but
I am still not getting text of studentId fields

Thanks its working fine know

is there any function in JQuery that can repalce
window.onload to some other way?

Don’t even worry about on load. Your code is already running at the end of the body, so on load is not needed. Just run the function.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.