jQuery: The Write Less, Do More JavaScript Library

Get dynamic width

View: New views
7 Messages — Rating Filter:   Alert me  

Get dynamic width

by eewan :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Hello,
I want to find full width of all elements in one div. Here is example
code:
<div id="scroller">
<p>text</p>
<p>text</p>
<p>text</p>
<p>text</p>
</div>


$("#scroller p").each(
function(i){
var elSize = $(this).width();});

I need total width of all <p> :-)

Thanks in advance

Re: Get dynamic width

by babwar :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


I'me not sure I understand ? : like this : ?

var tlSize = 0;
$("#scroller p").each(
function(i){
var elSize = $(this).width();
tlSize += elSize;
});

alert(tlSize);


On 3 juil, 13:24, eewan <ifi...@...> wrote:

> Hello,
> I want to find full width of all elements in one div. Here is example
> code:
> <div id="scroller">
> <p>text</p>
> <p>text</p>
> <p>text</p>
> <p>text</p>
> </div>
>
> $("#scroller p").each(
> function(i){
> var elSize = $(this).width();});
>
> I need total width of all <p> :-)
>
> Thanks in advance

Re: Get dynamic width

by babwar :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


like this ?
var tlSize = 0;
$("#scroller p").each(
function(i){
var elSize = $(this).width();
tlSize += elSize;
});

alert(tlSize);

On 3 juil, 13:24, eewan <ifi...@...> wrote:

> Hello,
> I want to find full width of all elements in one div. Here is example
> code:
> <div id="scroller">
> <p>text</p>
> <p>text</p>
> <p>text</p>
> <p>text</p>
> </div>
>
> $("#scroller p").each(
> function(i){
> var elSize = $(this).width();});
>
> I need total width of all <p> :-)
>
> Thanks in advance

Re: Get dynamic width

by Liam Potter :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


why not find the width of the div?

$("div#scroller").width();

eewan wrote:

> Hello,
> I want to find full width of all elements in one div. Here is example
> code:
> <div id="scroller">
> <p>text</p>
> <p>text</p>
> <p>text</p>
> <p>text</p>
> </div>
>
>
> $("#scroller p").each(
> function(i){
> var elSize = $(this).width();});
>
> I need total width of all <p> :-)
>
> Thanks in advance
>  

Re: Get dynamic width

by Jonathan Vanherpe (T & T NV) :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


eewan wrote:

> Hello,
> I want to find full width of all elements in one div. Here is example
> code:
> <div id="scroller">
> <p>text</p>
> <p>text</p>
> <p>text</p>
> <p>text</p>
> </div>
>
>
> $("#scroller p").each(
> function(i){
> var elSize = $(this).width();});
>
> I need total width of all <p> :-)
>
> Thanks in advance
>

The following seems to work for me:

var elSize = 0;
$("#scroller p").each(
function(i){
elSize+=$(this).width();});
console.log(elSize);

Jonathan
--
Jonathan Vanherpe - Tallieu & Tallieu NV - jonathan@...

Re: Get dynamic width

by eewan :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Thank you very much. This done the job :-)

Re: Get dynamic width

by eewan :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Thank you very much :-)