문제

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.

도움이 되었습니까?

해결책

.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"));

다른 팁

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/

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top