javascript - Finding the specific Tag a -
my html is:
<a id="showslotsbylocation_" href="#" style="color:blue;" onclick="confirmappt('28/05/2013','364301');">14.00 - 14.15</a> <a id="showslotsbylocation_" href="#" style="color:blue;" onclick="confirmappt('28/05/2013','364303');">14.15 - 14.30</a>
id name same on links. main difficulty.
i want click second link javascript code configure web browser is
if (location.pathname == "/abc") { //alert('location found') ok found; var el = document.getelementsbytagname("a"); (var i=0;i<el.length;i++) { if (el.id == 'showslotsbylocation_' && el.innertext.isequal('14.15 - 14.30') && el.outerhtml.contains("confirmappt('28/05/2013'")) { alert('link found') \\this condition not match; el.onclick(); } } }
what do match condition?
you can't have 2 element same id, ids unique.
when have changed ids, you'll can access them using document.getelementbyid('idofyourelement')
edit: first of all, need declare "current" variable takes current element in loop, can't use el.id
because el
collection of htmlelements! i'm sorry didn't noticed before. need this(define variable inside loop, before if statement):
var current = el[i];
now have defined it, change whole line code below.
if (el.id == 'showslotsbylocation_' && el.innertext.isequal('14.15 - 14.30') && el.outerhtml.contains("confirmappt('28/05/2013'"))
i think code stops you. there no functions called
isequal
,contains
in js.
if (current.id == 'showslotsbylocation_' && current.textcontent === '14.15 - 14.30' && current.outerhtml.indexof("confirmappt('28/05/2013'") !== -1)
one last thing: innertext isn't valid cross browser property, use textcontent instead.
updated js code
if (location.pathname == "/abc") { var el = document.getelementsbytagname("a"); (var i=0;i<el.length;i++) { var current = el[i]; if (current.id == 'showslotsbylocation_' && current.textcontent === '14.15 - 14.30')//i'm not sure one, in case want remove comment , last parenthesis && current.outerhtml.indexof("confirmappt('28/05/2013'") !== -1) { alert('link found'); current.click(); } } }
Comments
Post a Comment