What DOM properties and methods can I use to click on this element?

I wish I could modify the DOM (add a class or an id to the element...) but I cannot.

I need to click on this element:

<a href="javascript:__doPostBack('Results$_ctl5$_ctl0','')" style="color:#003069;">Address2</a>

Open in new window


I know I can select all anchor elements with e.g.
arefs := document.getElementsByTagName("a")

Open in new window


Not sure if that is the easiest way to begin, or whether there is a better way.

Can someone please provide the code that will click on that href using DOM properties/methods?

Thanks-
Sam
SAbboushiAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Chris StanyonWebDevCommented:
Going to be difficult without context. You can select elements that are children of other elements, or based on position within a container element (first, last, nth child etc) so where in the DOM does this sit?

We need to see it 'in context' to give you an answer
0
COBOLdinosaurCommented:
Just add an id to the element and the you can access it with document.getElementById()

Cd&
0
Chris StanyonWebDevCommented:
@Cd&

I wish I could modify the DOM (add a class or an id to the element...) but I cannot.
0
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

COBOLdinosaurCommented:
Yes I saw that and if they actually have such limited access that they cannot change a line of code then whoever or whatever is imposing that kind of restriction is obtuse, because you can do all kinds of damage in the DOM while at most you can only screw up a line of code if you have access.

@SAbboushi,

What we really need to know is what kind of nutty project puts you in a position where you cannot access the code but you have the ability to use scripting of the DOM that could literally destroy the page.

Cd&
0
SAbboushiAuthor Commented:
Maybe I have misled as a result of my "noobness"...

I do not have control over the webpage source; but I can change the DOM interactively by code in order to manipulate it (...if I said that correctly)  ; )

I wish I could modify the DOM (add a class or an id to the element...) but I cannot.

By this, I meant in the original html source; but if there is a way to add an id to the DOM after I have read the DOM, that would be good.

The href I want to click on is an element within a table:

TableHTML :=  document.getElementById("Table1").innerhtml

which contains e.g.

<tbody><tr>
		<td align="Center">&nbsp;</td><td><a href="javascript:__doPostBack('Results$_0','')" style="">Address</a></td><td align="Center"><a href="javascript:__doPostBack('Results$_1','')" style="">Owner</a></td><td align="Center"><a href="javascript:__doPostBack('Results$_2','')" style="">Price</a></td><td><a href="javascript:__doPostBack('Results$_3','')" style="">Bed</a></td><td><a href="javascript:__doPostBack('Results$_4','')" style="">Bath</a></td><td align="Center"><a href="javascript:__doPostBack('Results$_5','')" style="">SqFt</a></td>
	</tr><tr>
		<td align="Center"><input id="Results__ctl3" type="checkbox" name="Results:_ctl3" onclick="disableCheckBoxes(this.form);__doPostBack('Results$_ctl3$cbItem','')" language="javascript">
</td><td><a href="javascript:__doPostBack('Results$_ctl5$_ctl0','')">2707 RALPHO ST</a></td><td>JOHN SMITH</td><td align="Right">$237,416</td><td>04</td><td>02/1 </td><td align="Right">3,152</td>
	</tr>
</tbody>

Open in new window


In the above example, I want to click on: <a href="javascript:__doPostBack('Results$_ctl5$_ctl0','')">
0
Chris StanyonWebDevCommented:
As Cobol said, it does seem odd that you can inject javascript into a document but can't edit the HTML. There's no easy way of selecting that link because it has no unique identifier. You could do some complicated traversal to select it, but you'd need some consistency - i,e if it's always the last link in that table then you could use:

$('#Table1 a').last()

You could loop through every link and do a logical comparison against the href (but that's really messy)

Your best bet is to get an ID (or at least a Class) added to the A. If you can't get the HTML edited then you're probably out of luck on this one
0
SAbboushiAuthor Commented:
>> but can't edit the HTML

Let me make sure I understand: the webpage was created by another organization; we want to programatically navigate to an href on their page.  I would consider it unreasonable for me to contact another organization and ask them to change their website (i.e. add an id to an element) to accommodate our desire for an easy solution to have our code click on that link on their website.

That's what I mean by I cannot change the source HTML

>> There's no easy way of selecting that link because it has no unique identifier.
But "Results$_ctl5$_ctl0" is a unique identifier... or maybe there is a definition for "unique identifier" that I haven't yet learned...? I'm new a this  ; )
0
Chris StanyonWebDevCommented:
But "Results$_ctl5$_ctl0" is a unique identifier
No it's not. It's part of the href!

I'm not really following your logic on this one. It looks like you are wanting to use javascript to automatically click on a remote link. The whole concept is flawed - allowing javascript the ability to control the DOM of a remote page is a massive security concern and will just not work!

In order to select elements from the DOM you'll need to load the whole of the remote page into your script. You're then trying to 'click' a link from that page that has a javascript function as an href (bad design by the way). When you try and fire that click in your script it will fail because it will try and call a javascript function called __doPostBack() which you don't have!

I think you have to put this one to bed as a no-go. It's just not going to happen.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
SAbboushiAuthor Commented:
Thanks for your post.  Seems you have misunderstood mine.
0
SAbboushiAuthor Commented:
k thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
HTML

From novice to tech pro — start learning today.