Domanda

hey guys hope you can help me out.

I am relatively new to jquery and having some trouble traversing a table.

basically I have this

<tr>
                    <td>
                        <img src="120628SatchelTobyCole/thumbnails/SatchelTobyCole_0963.JPG" rel="#mies1" border="0" alt="SatchelTobyCole_0963.JPG">
                        <br />SatchelTobyCole_0963.JPG <input type="checkbox" name="SatchelTobyCole_0963.JPG"  value="SatchelTobyCole_0963.JPG">
                    </td>
                    <td>
                        <img src="120628SatchelTobyCole/thumbnails/SatchelTobyCole_0963c.JPG" border="0" alt="SatchelTobyCole_0963c.JPG">
                        <br />SatchelTobyCole_0963c.JPG <input type="checkbox" name="SatchelTobyCole_0963c.JPG" value="SatchelTobyCole_0963c.JPG">
                    </td>
                    <td>
                        <img src="120628SatchelTobyCole/thumbnails/SatchelTobyCole_0966.JPG" border="0" alt="SatchelTobyCole_0966.JPG">
                        <br />SatchelTobyCole_0966.JPG <input type="checkbox" name="SatchelTobyCole_0966.JPG" value="SatchelTobyCole_0966.JPG">
                    </td>
                    <td>
                        <img src="120628SatchelTobyCole/thumbnails/SatchelTobyCole_0966c.JPG" border="0" alt="SatchelTobyCole_0966c.JPG">
                        <br />SatchelTobyCole_0966c.JPG <input type="checkbox" name="SatchelTobyCole_0966c.JPG" value="SatchelTobyCole_0966c.JPG">
                    </td>
                </tr>

now I am pasting a part of code of a bigger function. Basically the part of code I am pasting is a little modification of the actual to explain the problem

src="SatchelTobyCole_0963c.JPG";
var checkbox=$("#getPix input:checkbox[name='"+src+"']");
alert(checkbox.parent("td").siblings("td").children("img").attr("src"));

Now I want the alert to say "120628SatchelTobyCole/thumbnails/SatchelTobyCole_0966.JPG"

BUT, instead, it is saying

"120628SatchelTobyCole/thumbnails/SatchelTobyCole_0963.JPG".

i.e, I want the alert to print the source of the next image in the table yet it is printing it of the previous?

if any one could explain what I am doing wrong and how to correct it I would be very greatful. thanks.

È stato utile?

Soluzione

.siblings gets all siblings and .attr gets the value of the first selected element. Try using .next() instead of .siblings() so that you get the next td's image rather than the first td's image.

alert(checkbox.parent("td").next().children("img").attr("src"));

Altri suggerimenti

You have to use next(). You can currently using parent.sibligs so it will find and its elements See JSFiddle here

http://jsfiddle.net/bMWZm/

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top