开发者

img SRC from first cell in a row with jquery

开发者 https://www.devze.com 2023-02-18 14:54 出处:网络
i have a table such that each row is like this <tr> <td><input/> <img id=\"foo\" src=\"redMinus.png\"/></td>

i have a table such that each row is like this

<tr>
<td><input/> <img id="foo" src="redMinus.png"/></td>
some more tds
<td> <a onclick="wow('foo',$(this))"></a>
</tr>

I want to find out if the img in the first td has an src that contains "redMinus" This is what I have but it doesnt s开发者_StackOverfloweem to be working?

function wow(id, item){
var tr$ = item.parentNode.parentNode;
var details = tr$.find('img[src*="redMinus"]');
}

Any ideas?

Thanks!


You're mixing jQuery with DOM elements.

Change your code to

var details = item.closest("tr").find('img[src*="redMinus"]');


Your parameter is given the name item within your function, but you are trying to use a variable with the name item$ instead. Either rename the parameter or use the correct parameter name in the function.


var same = "redMinus" == $(this).parent('td').prev().children('img').attr('src').substring(0,7);


function wow(id, item){
var src = $('#' + id).attr('src');
var srcIndex = src.indexOf('redMinus');
if(srcIndex >= 0)
// redMinus is present in the string
else
// redMinus is not present in the string
}
0

精彩评论

暂无评论...
验证码 换一张
取 消