0

I have a table uniquely identifying each row with a time-stamp. I want to have an anchor for each row.

Is there a way to avoid having to create a new "anchor" column and having to programmatically write <a name = "(row.ID}}" for each record?

If I have a unique time stamp in plain text format, can I create a virtual anchor?

The purpose is to have a user clicking on a reference to a comment from another page, auto-scroll to that comment, or, a user posting or editing a comment automatically scroll down to the row that he has just created or edited.

There are no element IDs and I don't want to write programming code to create the ID, for example:

<tr id="row9"><td>9</td></tr>
<tr id="row10"><td>10</td></tr>

I can, but was wondering if the plain text timestamp could be referenced some how. Rory has already mentioned that it's not possible without element ID.

Alex Glaros
  • 77
  • 1
  • 9
  • 1
    Yes - you can link directly to an element by its `id` by putting that `id` as the fragment in the URL. The window will scroll to put that element in view when the page loads. For example this links to the `#feed-link` element of the following page: http://stackoverflow.com/questions/105034/create-guid-uuid-in-javascript?rq=1#feed-link – Rory McCrossan Sep 09 '16 at 16:02
  • Question was not clearly posed. I'd like javascript to auto scroll to a place on the page identified by the date-time the post was made. For example, scroll to a comment posted on July 2, 2016 11:44 A.M. There are no DIV IDs or other structured anchors. – Alex Glaros Sep 09 '16 at 16:30
  • My comment addressed that - if you have an `id` on the element containing the comment you can just place that `id` after the `#` in the URL. You would only need JS for this if you want to animate the scrolling – Rory McCrossan Sep 09 '16 at 16:33
  • There is no ID. Just uniquely identifying plain text. Sorry I mistated the original question. – Alex Glaros Sep 09 '16 at 16:51
  • In that case, no. You would need to add an id or `` element – Rory McCrossan Sep 09 '16 at 17:05

1 Answers1

0

I am not sure if I understand your question correctly, if you can influence how the table is generated, you could add an unique id attribute on each <tr> element, and link to this from anywhere (including other pages) with an uri fragment (#id).

Below is a working demonstration of this approach (no javascript required):

<a href="#row97">Scroll to #row97</a>

<table>
<tr id="row0"><td>0</td></tr>
<tr id="row1"><td>1</td></tr>
<tr id="row2"><td>2</td></tr>
<tr id="row3"><td>3</td></tr>
<tr id="row4"><td>4</td></tr>
<tr id="row5"><td>5</td></tr>
<tr id="row6"><td>6</td></tr>
<tr id="row7"><td>7</td></tr>
<tr id="row8"><td>8</td></tr>
<tr id="row9"><td>9</td></tr>
<tr id="row10"><td>10</td></tr>
<tr id="row11"><td>11</td></tr>
<tr id="row12"><td>12</td></tr>
<tr id="row13"><td>13</td></tr>
<tr id="row14"><td>14</td></tr>
<tr id="row15"><td>15</td></tr>
<tr id="row16"><td>16</td></tr>
<tr id="row17"><td>17</td></tr>
<tr id="row18"><td>18</td></tr>
<tr id="row19"><td>19</td></tr>
<tr id="row20"><td>20</td></tr>
<tr id="row21"><td>21</td></tr>
<tr id="row22"><td>22</td></tr>
<tr id="row23"><td>23</td></tr>
<tr id="row24"><td>24</td></tr>
<tr id="row25"><td>25</td></tr>
<tr id="row26"><td>26</td></tr>
<tr id="row27"><td>27</td></tr>
<tr id="row28"><td>28</td></tr>
<tr id="row29"><td>29</td></tr>
<tr id="row30"><td>30</td></tr>
<tr id="row31"><td>31</td></tr>
<tr id="row32"><td>32</td></tr>
<tr id="row33"><td>33</td></tr>
<tr id="row34"><td>34</td></tr>
<tr id="row35"><td>35</td></tr>
<tr id="row36"><td>36</td></tr>
<tr id="row37"><td>37</td></tr>
<tr id="row38"><td>38</td></tr>
<tr id="row39"><td>39</td></tr>
<tr id="row40"><td>40</td></tr>
<tr id="row41"><td>41</td></tr>
<tr id="row42"><td>42</td></tr>
<tr id="row43"><td>43</td></tr>
<tr id="row44"><td>44</td></tr>
<tr id="row45"><td>45</td></tr>
<tr id="row46"><td>46</td></tr>
<tr id="row47"><td>47</td></tr>
<tr id="row48"><td>48</td></tr>
<tr id="row49"><td>49</td></tr>
<tr id="row50"><td>50</td></tr>
<tr id="row51"><td>51</td></tr>
<tr id="row52"><td>52</td></tr>
<tr id="row53"><td>53</td></tr>
<tr id="row54"><td>54</td></tr>
<tr id="row55"><td>55</td></tr>
<tr id="row56"><td>56</td></tr>
<tr id="row57"><td>57</td></tr>
<tr id="row58"><td>58</td></tr>
<tr id="row59"><td>59</td></tr>
<tr id="row60"><td>60</td></tr>
<tr id="row61"><td>61</td></tr>
<tr id="row62"><td>62</td></tr>
<tr id="row63"><td>63</td></tr>
<tr id="row64"><td>64</td></tr>
<tr id="row65"><td>65</td></tr>
<tr id="row66"><td>66</td></tr>
<tr id="row67"><td>67</td></tr>
<tr id="row68"><td>68</td></tr>
<tr id="row69"><td>69</td></tr>
<tr id="row70"><td>70</td></tr>
<tr id="row71"><td>71</td></tr>
<tr id="row72"><td>72</td></tr>
<tr id="row73"><td>73</td></tr>
<tr id="row74"><td>74</td></tr>
<tr id="row75"><td>75</td></tr>
<tr id="row76"><td>76</td></tr>
<tr id="row77"><td>77</td></tr>
<tr id="row78"><td>78</td></tr>
<tr id="row79"><td>79</td></tr>
<tr id="row80"><td>80</td></tr>
<tr id="row81"><td>81</td></tr>
<tr id="row82"><td>82</td></tr>
<tr id="row83"><td>83</td></tr>
<tr id="row84"><td>84</td></tr>
<tr id="row85"><td>85</td></tr>
<tr id="row86"><td>86</td></tr>
<tr id="row87"><td>87</td></tr>
<tr id="row88"><td>88</td></tr>
<tr id="row89"><td>89</td></tr>
<tr id="row90"><td>90</td></tr>
<tr id="row91"><td>91</td></tr>
<tr id="row92"><td>92</td></tr>
<tr id="row93"><td>93</td></tr>
<tr id="row94"><td>94</td></tr>
<tr id="row95"><td>95</td></tr>
<tr id="row96"><td>96</td></tr>
<tr id="row97"><td>97</td></tr>
<tr id="row98"><td>98</td></tr>
<tr id="row99"><td>99</td></tr>
</table>
Tomas Langkaas
  • 4,551
  • 2
  • 19
  • 34