Javascript is not positioned correctly

I'm having problems with my javascript. I have to colocate an image in a specific position. The user gives me a date and I put an image for the correct month of the year. For example if they put 01/05/1936, an image appears on a table in the row "1936" on the colummn "5" , so I have 2, each one for the years an another for the months. The month is correct but it puts the image in all rows, and I don't know why, here is my code:

On the HTML part I only have a table with id="tabla" and 2 rows one with id="1935" and the other with id="1936", each td has the class of the correct month:

<tr id="1935"> <th>1935</th> <td class="E"></td> <td class="F"></td> <td class="M"></td> <td class="A"></td> <td class="Y"></td> <td class="J"></td> <td class="L"></td> <td class="G"></td> <td class="S"></td> <td class="O"></td> <td class="N"></td> <td class="D"></td> </tr> <tr id="1936"> <th >1936</th> <td class="E"></td> <td class="F"></td> <td class="M"></td> <td class="A"></td> <td class="Y"></td> <td class="J"></td> <td class="L"></td> <td class="G"></td> <td class="S"></td> <td class="O"></td> <td class="N"></td> <td class="D"></td> </tr>

` Javascript code

var filas=document.getElementById("tabla").rows.length;//I count the rows, years var cols = $("#tabla").find('tr')[0].cells.length;//I count the td, months $("tr").each(function(a){ var fila= $(this); alert("Primer alert"+fila.attr("id")); if (fila.attr("id")==anio) { $("td").each(function(a) { var col=$(this); alert("segundo alert"+col.attr("class")); if (col.attr("class")==mon) { $(this).prepend('<img id="black_point" src="./images/circle.png"/>'); } }); } });`

-------------Problems Reply------------

With jQuery, looping can very often be avoided.

As far as I can tell, you can select the correct table cell with a single jQuery selector ...

function foo(anio, mon) {
$('#' + anio + ' .' + mon).prepend('<img id="black_point" src="./images/circle.png"/>');

Please note that I have assumed a function wrapper not shown in the question.

You're going through all tds not only the ones inside that tr, so you need to change:




Category:javascript Views:2 Time:2018-04-15

Related post

  • NavigationBar not positioned correctly. How to solve this problem? 2011-09-21

    I have a Navigation Controller in my main view and also subview. And I use the following code to add the navigation view when needed. In appdelegate.h page @interface AapkeappsAppDelegate : NSObject <UIApplicationDelegate, UINavigationControllerDe

  • javascript did not load correctly 2014-07-27

    What do I need to do/add/download in order to get JavaScript to download correctly. I need access to the Shutterfly share page for my daughter's team. I can get to the home page but every tab I click on says "JavaScript did not load correctly." -----

  • UITableViewCell accessory not positioned correctly after rotating UITableView on iPad 2010-09-17

    I have an iPhone app that I've converted to a universal app. The app works fine in all orientation on the iPhone. However on iPad when I rotate a table view, the UITableViewCell accessory is not repositioned correctly (see images below). I'm using a

  • Empty JPanel not positioning correctly in relation to other JPanels 2012-04-09

    I am using swing to build a GUI with 4 JPanels inside a JPanel using the BorderLayout manager: A row of labels A column of JButtons A display area (it is a class that extends JPanel and has nothing added to it and is used as a drawing area) Another c

  • UIView's are not positioning correctly 2010-12-20

    I have a nib with a 2 UIViews and 2 UILabels with IBOutlet's in my controller. I am increasing and decreasing the height of these UIViews to look like a bar to indicate when something is 100% or less - like a bar chart almost. I am using the followin

  • MySQL Timestamp to JavaScript Date not converting correctly 2011-01-13

    so I have a timestamp in mysql that is: SELECT `tsdate`, UNIX_TIMESTAMP( `tsdate`) FROM t1 2010-11-07 21:50:05, 1289191805 If I try and use the following, it displays the wrong time/date var newDate = new Date(); newDate.setTime(1289191805000); dateS

  • iTextSharp CreateLink / JavaScript annotation not displaying correctly 2011-02-16

    I'm getting a memory stream in and then trying to append a link annotation with calls some JavaScript. Simply put my code looks like: PdfReader pdfReader = new PdfReader(streamFromSharePoint); PdfStamper pdfStamper = new PdfStamper(pdfReader, pdfMemo

  • label not positioning correctly? 2012-05-01

    I have made a div of "alert box i am making". I can not position the text in the center of the title part. I have tried to add padding, and margins, but they do not work. --------------Solutions------------- Take

  • javascript function not behaving correctly 2008-12-15

    I have this little function function makewindows(){ child1 = ("about:blank"); child1.document.write("<?php echo htmlspecialchars(json_encode($row2['ARTICLE_DESC']), ENT_QUOTES); ?>"); child1.document.close(); } Which whatever I try,

  • Javascript table not working correctly 2010-05-21

    I´m trying to figure out why that table is showing like that, I mean, how to set every col to ocuppy the full width of the table frame? here´s the function that creates the table: function rp_insertTable() { FM_log(3,"rp_insertTable() called"); var f

  • NavigationBar from UINavigationController not positioned correctly 2010-05-26

    So, my iPad program has a pseudo-split view controller (one that I implemented, not base SDK one), and was working correctly a while ago. It has the basic layout (UINavController for master, content view controller for detail on right), but I have it

  • IE7 Javascript Hover not Working Correctly 2011-05-31

    I have made a simple Javascript on hover effect so when you hover a div the text is then displayed in the div below, but in IE7 only a random few will work such as 1,2,3,4,27,28 and a few others the rest just do not work? Here is my code: <!DOCTYP

  • Javascript function not working correct in IE and Chrome, image not change if image in inside a accordion 2012-01-11

    I have ASP.NET site. At the master page I have javascript code. $(document).ready(function () { var img = $("img"); img.each(function (index, element) { if (img[index].complete == true) { Pixastic.process(img[index], "desaturate", {}); } else { img.l

  • Javascript getElementsByTagName not pulling correctly in IE8 2012-04-26

    I'm working out bugs that a coworker left on a page that posts a form to an API, and receives the XML response in an iframe, then parses through the children with XML. The page is working in IE9, Chrome, and Firefox, but not IE 8. the form: <form

  • Javascript files not mapping correctly in ASP.NET MVC? 2009-03-04

    I am having an issue with my javascript files in a master page ... I have the following: <script src="Scripts/jquery-1.2.6.min.js" type="text/javascript"></script> <script src="Scripts/Plugins/jquery-corners.js" type="text/javascript"

  • Why is the p background not positioning correctly? 2010-01-21

    Can you please tell me why the p background is not showing? The issue is only in firefox. Firebug is showing the div positioning behind the floated divs above, but can't figure out why. I know the image is there and showing, but is behind the other d

  • Dojo: dijit.form.DropDownButton content not positioned correctly 2010-03-29

    I have the following setup: <div dojoType="dijit.form.DropDownButton"> <span>Modify</span> <div dojoType="dijit.Menu"> <div dojoType="dijit.MenuItem">...</div> </div> </div> There is of course more to t

  • Javascript Array not working correctly with $.makeArray 2011-02-21

    I'm trying to make an array out of a set of div's on a page using jQuery. I basically want to randomise the way they are displayed so for the moment, I'm just trying to cycle through them. Everything appears to work, except that I only ever see the l

  • Abs. positioned element inside Button is not positioned correctly 2011-05-27

    I'm trying to put an icon inside a button element and I'm getting strange positioning but in Firefox 4. Check out this demo It works as expected in Chrome and IE but in Firefox the icon is completely off the reservation.

  • firefox 4 - comet iframe, pushes(javascript) are not executed correctly 2011-06-22

    I have an application that uses forever iframe(comet), this is working fine in firefox 3.6. But in firefox 4, pushes(javascript code that is sent from server) are not executed properly means firefox 4 is skipping some pushes, I have checked with fire

  • javascript menu not performing correctly in explorer 8 (works fine in chrome and explorer 8 compatability mode) 2011-07-01

    i'm building a website template which you can see here: all was going well until i checked in explorer (8) on pc (i normally use chrome on pc) the problem relates to the (left hand) side menu... i no

  • Jquery tooltip with offset not positioned correctly? 2011-12-10

    I am using the Jquery tooltip form this .Its working awesome.But one condition it gets failure.When the divs are displayed with in the div with fixed he

  • Address not positioned correctly on envelope 2012-04-29

    In Office 2003 I could attach an envelope to a letter and it would print the address in the correct position on the envelope. I cannot get Office Word 2010 to do this even though I load the envelope correctly and select correct size envelope. Can som

  • sized div containing a scaled div not positioning correctly 2013-01-10

    I'm sorry for the overly specific question heading but I have no idea what more general thing could be going on. Clearly I'm missing something Take a look at this jsbin: Note that you have to look at it in edit mode, fo

  • Image inside a button not positioned correctly in Firefox 2010-03-07

    I have the following markup: <p class="managebox"> <button value="Add page"> <img src="page_add.png" alt="Add more content" /> Add Page </button> </p> And the following CSS: p.managebox { position: relative; } p.managebo

Copyright (C), All Rights Reserved.

processed in 0.071 (s). 11 q(s)