jQuery - how can I find the element with a certain id?

后端 未结 5 1851
故里飘歌
故里飘歌 2020-12-25 11:42

I have a table and each of its td has a unique id that corresponds to some time intervals (0800 til 0830... 083

相关标签:
5条回答
  • 2020-12-25 11:55

    I don't know if this solves your problem but instead of:

    $("#tbIntervalos").find("td").attr("id", horaInicial);
    

    you can just do:

    $("#tbIntervalos td#" + horaInicial);
    
    0 讨论(0)
  • 2020-12-25 11:56

    As all html ids are unique in a valid html document why not search for the ID directly? If you're concerned if they type in an id that isn't a table then you can inspect the tag type that way?

    Just an idea!

    S

    0 讨论(0)
  • 2020-12-25 12:01

    This is one more option to find the element for above question

    $("#tbIntervalos").find('td[id="'+horaInicial+'"]')

    0 讨论(0)
  • 2020-12-25 12:02

    If you're trying to find an element by id, you don't need to search the table only - it should be unique on the page, and so you should be able to use:

    var verificaHorario = $('#' + horaInicial);
    

    If you need to search only in the table for whatever reason, you can use:

    var verificaHorario = $("#tbIntervalos").find("td#" + horaInicial)
    
    0 讨论(0)
  • 2020-12-25 12:02

    This

    var verificaHorario = $("#tbIntervalos").find("#" + horaInicial);
    

    will find you the td that needs to be blocked.

    Actually this will also do:

    var verificaHorario = $("#" + horaInicial);
    

    Testing for the size() of the wrapped set will answer your question regarding the existence of the id.

    0 讨论(0)
提交回复
热议问题