Reputation: 2060
I am trying to use the web developer tool 'Web Console' along with 'Firebug'. I am trying to simulate what happens when I click on this button by entering in a script to the webconsole but it isn't working. Can someone help me figure out what to enter in the Web Console? I asked my boss for help but he said this is the last straw!! Please help.
Here is the code with the button....
<div id="car_perf_internal" style="display: inline;">
<span style="float:left;"> </span>
<div class="select_box right nccDropToggleSection">
<a id="Left" class="NCCPUSHBUTTON" href="javascript:;" onclick="iToggleDisplay(this, 'nccDropToggleSection', 'nccDropToggleContent', null, null, 2);">
<span>
<input id="buttons_K_NC_TITLE" class="NCCPUSHBUTTON" type="button" value="Performance Documents" name="buttons_K_NC_TITLE">
</span>
</a>
I tried entering this into the web console, but it said 'TypeError: a is undefined'
iToggleDisplay('Left', 'nccDropToggleSection', 'nccDropToggleContent', null, null, 2);
Upvotes: 0
Views: 215
Reputation: 30453
If you place some code in html in event attribute, then this
points to the dom object (in your case to the link with id Left
). To get this you may get it by id with document.getElementById
function:
iToggleDisplay(document.getElementById('Left'), 'nccDropToggleSection', 'nccDropToggleContent', null, null, 2);
But you can emulate button click this way:
document.getElementById('Left').click();
Upvotes: 0
Reputation: 9174
You have to pass the actual DOM
node and not the id
as the first parameter
So instead of
iToggleDisplay('Left', 'nccDropToggleSection', 'nccDropToggleContent', null, null, 2);
it should be
iToggleDisplay(document.getElementById('Left'), 'nccDropToggleSection', 'nccDropToggleContent', null, null, 2);
Because this
refers to the node itself
Upvotes: 0
Reputation: 28795
Left
isn't a dom element, it's the ID value. You need to convert it to an element:
iToggleDisplay(document.getElementById('Left'), 'nccDropToggleSection', 'nccDropToggleContent', null, null, 2);
Upvotes: 2
Reputation: 207501
It appears you need to pass the reference to the element, not just an id.
iToggleDisplay(document.getElementById('Left'), 'nccDropToggleSection', 'nccDropToggleContent', null, null, 2);
other option is to call click
var elem = document.getElementById("Left");
elem.onclick.apply(elem);
Upvotes: 0