Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6952615
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:22:19+00:00 2026-05-27T14:22:19+00:00

I have the following HTML… <body onload=draw();> <p><a href=><canvas class=demo2 width=6 height=12>Fallback</canvas> Back to

  • 0

I have the following HTML…

<body onload="draw();">

  <p><a href=""><canvas class="demo2" width="6" height="12">Fallback</canvas> Back to (1)...</a></p>
  <p><a href=""><canvas class="demo2" width="6" height="12">Fallback</canvas> Back to (2)...</a></p>

</body>

…and javascript:

function draw() {        
    var canvas2 = $('.demo2').get(0); // This draws in the first canvas
    //var canvas2 = $('.demo2').get(); This doesn't draw at all
    if (canvas2.getContext) {
        var ctx2 = canvas2.getContext('2d');

        ctx2.beginPath();
        ctx2.moveTo(6,0);
        ctx2.lineTo(6,12);
        ctx2.lineTo(0,6);
        ctx2.fillStyle = 'rgb(0,100,220)';
        ctx2.fill();
    }
}

What I’d like to happen is for the all canvases with the class demo2 to be drawn in.

I thought $('.demo2').get() would get all elements by that classname. $('.demo2').get(0) draws in the first one but I’d like to draw in them all.

Demo at http://jsfiddle.net/kMN3s/

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T14:22:20+00:00Added an answer on May 27, 2026 at 2:22 pm

    You can use .each to execute things for each .demo2: http://jsfiddle.net/kMN3s/2/.

    function draw() {        
        $('.demo2').each(function() {
            if (this.getContext) { // `this` is an element each time
                var ctx2 = this.getContext('2d');
    
                ctx2.beginPath();
                ctx2.moveTo(6,0);
                ctx2.lineTo(6,12);
                ctx2.lineTo(0,6);
                ctx2.fillStyle = 'rgb(0,100,220)';
                ctx2.fill();
            }
        });
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have following HTML markup, <div id=subcontent_l> <p> <a href=/membership-packages/><img height=202 width=644 alt= src=http://74.52.72.231/wp-content/uploads/2010/06/banner1.jpg
I have the following html <div id=menu> <ul class=horizMenu> <li id=active><a href=# id=current>About</a></li> <li><a
I have the following HTML: <tr> <td class=ui-widget-content> <a title=Edit href=/Administration/Menus/Edit/001W class=editLink ui-button ui-widget
I have the following HTML: <input type=text id=endDateEditBox value= style=margin-left:5px; height:18px; width:70px; vertical-align:middle; onchange=validateDate('endDateEditBox',
I have following html: <table width=100%;> <tr><hr style=width:100%;></hr></tr> <tr> <span style=float:left>abc</span> <span class=noindex style=float:right>PageID</span>
I have following HTML <div id=finalTree> <ul> <li class=last style=display: list-item;> <a id=DataSheets href=#>Data
i have following HTML code:- <table class=results> <tr> <td> <a href=..>link</a><span>2nd Mar 2011</span><br>XYZ Consultancy
I have following HTML table: <form method=post action=update-table.php> <table class=table-data style=width: 960px;> <thead> <tr>
I have the following html: <a href=javascript:<%# 'js code' %> class=MyClass> <div class=HeaderRow style=vertical-align:middle;text-align:left;height:35px;width:998px;>
I have the following HTML code: <div id=Activity class=rep_tb0 style=width: 100%> <div class=rep_tr0 style=width:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.