0

I am using a third party grid to display some data and I dont have any control over the markup it produces

In the example below, I'd like to hide the submit buttons for the rows where the adjacent cell has no value (i.e. the middle row in the example below)

I assume this is possible with jQuery but am a bit stuck on how to do stuff conditionally

<div id="grid"> <table> <tr> <td>123</td><td><a href="/go/somewhere">Submit</a></td> </tr> <tr> <td></td><td><a href="/go/somewhere">Submit</a></td> </tr> <tr> <td>123</td><td><a href="/go/somewhere">Submit</a></td> </tr> </table> <div> 

any ideas?

3 Answers 3

1

I think this should work, I've tried in http://jsfiddle.net/Bu5eZ/ and it's working as expected.

var cells = $("table tr td:first-child"); cells.each(function(i){ if ($(this).text() === ''){ $(this).next().find('a').hide(); } }); 
Sign up to request clarification or add additional context in comments.

Comments

1

You could use the .filter() jQuery method, inserting your own logic inside of it.

$('a').filter(function () { return $(this).closest('tr').find('td:first-child').html() === ''; }).hide(); 

Chaining a simple .hide() at the end.

Edit, changed to td:first-child, speeds it up.

Comments

1

Demo: http://jsfiddle.net/ChgMx/1/

$("#grid a").each(function(i,k){ if($(k).parent().prev().text().length == 0) $(k).hide(); }); 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.