0
         <tr phrase_id="1" class="altRow">   
        <td style="padding:3px; vertical-align:top;"><input type="checkbox" value="1"></td>
        <td class="phraseCode" style="padding:3px; vertical-align:top;">EUH 201/201A</td>
        <td class="phraseText" style="padding:3px; vertical-align:top;">Contains lead. Should not be used on surfaces liable to be chewed or sucked by children. Warning! Contains lead.</td>
      </tr>

The above code is extracted from a web page using F12 in chrome.In the above code there is a checkboxwhich when clicked turns the whole row yellow.So I made a bookmarklet which will check that checkbox ,but it is not making the line yellow.here is my bookmarklet

javascript:(function(){var s = document.getElementsByClassName("phraseCode");for(i=0;i<s.length;i++){if(s[i].innerText=="EUH 201/201A"){s[i].parentNode.getElementsByTagName("input")[0].checked=true;break;}}})();

it checcks the checkbox but not updating the row to yellow.Why?can anyone explain me please?

Satya
  • 49
  • 1
  • 8
  • 1
    Changing the checked state programmatically doesn't trigger the change event; you have to fire that manually. – David Thomas Nov 05 '14 at 19:58
  • 1
    var elm=s[i].parentNode.getElementsByTagName("input")[0]; elm.checked=true; elm.onchange(); – dandavis Nov 05 '14 at 19:58
  • @dandavis I already tried the above method ,but it is not working. – Satya Nov 05 '14 at 20:35
  • if jq is around then $(elm).change() usually works, otherwise you need to manually trigger the event listener, which is complicated to do universally in vanilla. – dandavis Nov 05 '14 at 21:01
  • @dandavis I tried `typeof()` to get the type of `onchange`event.it shows `object` rather than `function`.So what could be the problem? – Satya Nov 06 '14 at 04:42
  • @Satya: it means it's null, the default dom binding placeholder, because null is an object. this means the main script is watching for changes using addEventListener(), which means there is no event method to call. look into http://stackoverflow.com/questions/2490825/how-to-trigger-event-in-javascript – dandavis Nov 06 '14 at 05:34

0 Answers0