0

I am trying to get div from 15th td column and set width of div to 300px.

I have table summary to recognize the table. How to do set width?

<table  summary="Copy and Design RFP">
....
...
/* column15*/
<td class="ms-vb2">
    <div dir="">1/9/14 - 1st draft sent</div>
</td>

So far I wrote

 $(document).ready(function () {
        if (window.location.href.indexOf("dept/mkt/Lists/Request for Projects/Active Projects.aspx") > -1) {
            $('table[summary="Copy and Design RFP"] tr td:nth-child(15)').each(function() {
                var id = $(this).find('div'); // This is not working
            });
        }
    });
1
  • $('table[summary="Copy and Design RFP"] td:eq(14) div').width(300) Commented Jun 9, 2014 at 19:32

2 Answers 2

2

Use the nth-child selector:

$('table[summary="Copy and Design RFP"] td:nth-child(15) div').css('width', '300px');
Sign up to request clarification or add additional context in comments.

5 Comments

You do have metacharacters in your selector that may need to be escapped.
Maybe you could tell us why your version works and the OP's doesn't, as you're using almost the same selector ?
OP's stopping the search at the td level, then doing an each, trying to find any divs which are children of that already child element. unless the node has td div div, the search will find nothing.
Not really, the each() is called on the single TD element, and inside it does $(this).find('div') where this would be the TD, which would be the same as your selector, so why would your selector find it and not the OP's each() call, however strange it is ?
My bad!! @War10ck I was referring to MarcB's answer but I was mistaken.
0

I create this solution:

js

var i = 1;
$("table tr").children().each(function(){
    if(i==15){
     var div = $(this).find("div");
     $(div).attr("style","height:300px;");
    }
    i++;
});

fiddle

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.