Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!.POSTED!not-for-mail From: "J.R." Newsgroups: comp.lang.javascript Subject: Re: Difference between findPos("divThis") and findPos(divThis) Date: Sun, 13 Nov 2011 18:55:32 -0200 Organization: Aioe.org NNTP Server Lines: 44 Message-ID: References: <4775241.ypaU67uLZW@PointedEars.de> <2394720.ArG6xLiZAS@PointedEars.de> NNTP-Posting-Host: edb3lPNLwDIT/BKKc/Xuzw.user.speranza.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: Mozilla/5.0 (Windows NT 6.0; rv:8.0) Gecko/20111105 Thunderbird/8.0 X-Notice: Filtered by postfilter v. 0.8.2 Xref: x330-a1.tempe.blueboxinc.net comp.lang.javascript:8293 On 13/11/2011 18:04, Cal Who wrote: > > >> But I will still ignore you if you (continue to) post with an invalid >> From/Reply-To header field value. Usenet can only work if communication >> works both ways. > > I have no idea what it is about. I use IE Express and reply with "Reply > Group" > Do I have something set up wrong? > ' >> >>> Is the first approch (var w = document.getElementById(obj).offsetWidth) >>> the better one? >> >> Yes and no. It is the better one if you pass the element's ID string for >> `obj'. It is not better if you call document.getElementById(obj) twice in >> the process. There are also cases where you do not need to call >> document.getElementById(); in that case it would be better not to call it. >> > > That's what I'll do then. > > Thanks > > I always use obj as a reference to an element of the DOM. But I admit there are cases in which you would like to receive either a string or an element reference as the function's argument. In this case, try this code: function getOuterDimensions(obj) { var el = (typeof obj == 'string') ? document.getElementById(obj) : obj, w = el.offsetWidth; h = el.offsetHeight; ... } Please, have a look at the post called "David Mark's Javascript Tip Du Jour - Volume #1 - Tip #1234 - How to Measure Element Dimensions". -- Joao Rodrigues (J.R.)