I am a newbie to JQuery. I went through a Lynda.Com tutorial but I still don't quite 'get it' with the selectors.
I have a SharePoint view which displays a number with 4 decimal positions and I want to change it to 2. I can't do this with OTOB SharePoint but I should be able to do it with JavaScript and JQuery (if I had the skillset for it.)
Part of the problem is SharePoint doesn't always provide ID's and other distinguishing items in their html to facilitate the selections. Imagine that.
So my table has the following structure:
<tr class=" ms-itmHoverEnabled ms-itmhover" ...
This is OK. I don't really understand the two classes separated by a space, but this turns each row red.
$("tr.ms-itmhover").css("background-color", "red");
But what I want is a cell from each row. There are numerous TD's following the TR, some with different classes and the like, but most of the columns look like this, although the value changes depending on which column. This one is the one I want with the number I need to reformat. There are 12 of these TD's and the one I want is the 8th:
<td class="ms-cellstyle ms-vb2">65146.0000</td>
This line of code selects all of the cells in the grid with that ms-vb2 class so most of the view is red, except the first couple of columns which have a different class.
$("tr.ms-itmhover td.ms-vb2").css("background-color", "red");
At this point it's kind of promising. I am getting all of my TD's in the view. But I want the 8th column so I thought this would work.
$("tr.ms-itmhover td.ms-vb2:eq(8)").css("background-color", "red");
Well, this gets the right cell on the first row only. Al the other rows get nothing. So here I get stuck and don't know quite what to do to get this cell from all rows.
The next problem I will have is once I get all of the columns selected, I am not sure how to iterate through them and reformat the number, but I guess I will cross that bridge when I get to it.
Any help would be appreciated. Thanks.