From: Cal Who on
I need Javascript code to recursively search for a element given the
element's Id so that I can modify a elements attributes.

I do not use JQuery but I believe that once when I was searching the
Internet for something else I saw that JQuery has a function called $ that
did just that. And the author showed the Javascript code from that library.
I'm not sure if that is what I need but now that I want it I can't find it.

Bottom line: Can you point to (or supply) Javascript code to recursively
search for a element given it's Id?



Thanks in advance


From: Registered User on
On Sat, 22 May 2010 14:38:38 -0400, " Cal Who"
<CalWhoNOSPAM(a)roadrunner.com> wrote:

>I need Javascript code to recursively search for a element given the
>element's Id so that I can modify a elements attributes.
>
>I do not use JQuery but I believe that once when I was searching the
>Internet for something else I saw that JQuery has a function called $ that
>did just that. And the author showed the Javascript code from that library.
>I'm not sure if that is what I need but now that I want it I can't find it.
>
>Bottom line: Can you point to (or supply) Javascript code to recursively
>search for a element given it's Id?
>
Perhaps you mean something like

var element = document.getElementById('someID');

regards
A.G.
From: Cal Who on
That's what I thought but lost confidence when it returned null in the
following:

<script type="text/javascript">

function SetMargins(id) {

var element = document.getElementById(id);

....

Which is in the .master and the id looks like I'd expect:

id = "ctl00_BottomImageCPH_QQQ"



I called it from and aspx.vb file

<asp:Content ID="Content8" runat="server"
ContentPlaceHolderID="BottomImageCPH">

<script type="text/javascript">

SetMargins('<%=QQQ.ClientID%>');

</script>


<div runat="server" id="QQQ" style="margin-left: 10%; margin-right: 10%;" >

....


Why the null??


Thanks


From: Mark Rae [MVP] on
" Cal Who" <CalWhoNOSPAM(a)roadrunner.com> wrote in message
news:ht9l9g$dti$1(a)news.eternal-september.org...

> Why the null??

Because of ASP.NET's control ID munging.

var control = document getElementById('<%=MyControl.ClientID%>');


--
Mark Rae
ASP.NET MVP
http://www.markrae.net

From: Registered User on
On Sat, 22 May 2010 18:19:25 -0400, " Cal Who"
<CalWhoNOSPAM(a)roadrunner.com> wrote:

>That's what I thought but lost confidence when it returned null in the
>following:
>
><script type="text/javascript">
>
>function SetMargins(id) {
>
>var element = document.getElementById(id);
>
>...
>
>Which is in the .master and the id looks like I'd expect:
>
>id = "ctl00_BottomImageCPH_QQQ"
>
>
>
>I called it from and aspx.vb file
>
><asp:Content ID="Content8" runat="server"
>ContentPlaceHolderID="BottomImageCPH">
>
><script type="text/javascript">
>
>SetMargins('<%=QQQ.ClientID%>');
>
></script>
>
>
><div runat="server" id="QQQ" style="margin-left: 10%; margin-right: 10%;" >
>
>...
>
>
>Why the null??
>
From the second snippet it appears the SetMargins method is being
called as the document is rendered. The document is rendered from top
to bottom. If SetMargins is called before control QQQ is rendered to
the document, the document won't find the control, and
document.getElementById will return null.

You may have to read that last sentence a couple of times ;)

I would suggest attaching a javascript method to the page body's
onload event. That method will be called after the page has been
rendered. From within that method make the call to SetMargins.

regards
A.G.