logo
down
shadow

Javascript - Call function when clicking on a svg shape.


Javascript - Call function when clicking on a svg shape.

By : Parminder
Date : November 22 2020, 10:38 AM
may help you . I would change the way you're implementing this a bit. Instead of using a different inline click event handlers for each rectangle, delegate a single click event programmatically to all rectangles. To differentiate which character should be appended, you can add data attributes to your rectangles that contain the character they represent and retrieve their values in the click handler. To handle physical keyboard input, you have a separate event binding specifically for that. Here's a working example of how I would approach this, with some comments for clarification on what it's doing.
code :
    function yourOtherFunction(input) {
         console.log('You typed a "' + input + '"');   
    }
    
    $(function() {
        // Handle on-screen keyboard clicks (only on rects with a data-character
        // attribute present)
        $('svg rect[data-character]').click(function() {
            // Retrieve the "data-character" attribute value
            var character = $(this).data('character');
            // Modify the value of the textarea by appending the character
            $('#text').val(function(i, old) { return old + character; });
            // Call your other function
            yourOtherFunction(character);
        });

        // Handle physical keyboard key presses:
        $('#text').keypress(function(e) {
            // Retrieve the character representation of the event's key code
            var character = String.fromCharCode(e.which);
            // Call your other function
            yourOtherFunction(character);
        });
    });    
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

    <svg width="60px" height="60px">
        <rect width="50" height="50" data-character="a" />
    </svg>
    <svg width="60px" height="60px">
        <rect width="50" height="50" data-character="b" />
    </svg>
        
    <textarea id="text"></textarea>


Share : facebook icon twitter icon
How to call a javascript function with Lift after clicking a button?

How to call a javascript function with Lift after clicking a button?


By : Oliver Crosby
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further SHtml.button takes as an argument () => Any so any JavaScript will not get returned to the browser and executed.
I would do one of two things:
how can i call javascript function when clicking on image?

how can i call javascript function when clicking on image?


By : TheLord
Date : March 29 2020, 07:55 AM
wish helps you How can I call a js function so it work on click image? ,
Add an ID (remove your onclick thingy):
code :
<img src="images/divclose.png" alt="*" id="closeButton" />
$(function () {
  $("#closeButton").click(function () {
    $("#sheet").css("display", "none");
  });
});
In PHP code on clicking a link javascript function call

In PHP code on clicking a link javascript function call


By : Hutch
Date : March 29 2020, 07:55 AM
nothing happens when clicking button to call javascript function

nothing happens when clicking button to call javascript function


By : user7265156
Date : March 29 2020, 07:55 AM
will help you The problem seems to be too simple, the text within the confirmation is not properly concatenated. Hence it was not working.
code :
 var ok = confirm("Click OK to show the time, \n or click Cancel to close this window \n   
//--- an enter key is pressed     
without doing anything.");
How to call JavaScript function in HTML without clicking any button?

How to call JavaScript function in HTML without clicking any button?


By : Edwin Briones
Date : March 29 2020, 07:55 AM
I hope this helps you . My function is a timer that should run when the page is displayed. I wrote
code :
<script>
window.onload = function() {
   startcountdown();
}
</script> 
Related Posts Related Posts :
  • How to change add and remove active class in JavaScript
  • how to toggle a specific div in javascript
  • How to get all the values from multiple keys of an array of object?
  • jQuery bind() unbind() and on() and off()
  • regular expression to find DD Month YYYY from a string
  • How to upload files from web client (HTML/jQuery form) to your Dropbox folder
  • Backbone history and require.js issue
  • Confusion over Classical and Prototypal Inheritance Javascript
  • How to take screen shot of current webpage using Javascript/JQuery?
  • Store meridiem in a variable
  • class declared inside closure vs standard class without closure
  • javascript confirm box always return true
  • dynamically changing the size of font size based on text length using css and html
  • Node.js - Getting the host IP address while on Amazon EC2
  • Confusing CSS, can anyone explain please
  • How to install v8-profiler on Windows 8 (64 bit) using npm?
  • Resolve promise based on another promise
  • google maps adding overlay layer above UI and markers
  • Style specific letter?
  • RangeError: Maximum call stack size exceeded with array.slice
  • node rest client get with local variable
  • If condition not executes while mouse move fastly
  • Count the number of displayed elements in a HTML list
  • Locate JavaScript source code in Emacs
  • Clean, Modular Code vs MV* Frameworks
  • infinite scroll without loading image
  • Backbone: reverse collection order with comparator
  • What do printers ignore?
  • jQuery UI .tabs() Contentless tab?
  • Execute Javascript alert() after page (visually) loaded
  • JavaScript - duplicating array doesn't work
  • Excessive clickable area below image
  • JavaScript Regex: Replace |b| with <b>
  • Unexpected value change in 2D array in JavaScript
  • Function doesnt see parameter as a array of objects
  • jQuery fetch keypress event on chrome and IE
  • How to enable jquery validate localization?
  • Cassandra map collection returned by node.js Helenus looks odd
  • angular ng-repeat with multiple filter options
  • Selecting Children without ID or Class names
  • How to uncheck a group of checkboxes when another checkbox is checked
  • Is hiding content by Javascript or jQuery Worth trying
  • Load XUL resource using javascript
  • XML to HTML text area from server file system
  • set focus() on textbox on form onload
  • es lint '' is assigned a value but never used' eventhough i have used it
  • Can "name" attribute be used for custom VueJS components
  • Get innerHTML of content when it is clicked
  • HTTPS causes CSS animations to not load? Very confused
  • How to hide other div apart from touched div to the band
  • Is global variable assignment atomic on NodeJS?
  • Datepicker onchangemonthyear beforeshowday
  • trying to render html files using jade but it still adresses it as a jade
  • Google Analytics - Understanding and Dissecting the Snippet: What is | | [ ];
  • Replacing "[aA09.b]." to "[aA09.b]\n" in in JavaScript
  • Why wrap a function definition in an immediate function?
  • Enable / disable jQuery script on switching to different tab in a HTML page
  • how can find return variable value outside anonymous function in node js mysql query function
  • Converting 1 to 0001 in javascript array
  • svg viewbox should not resize the text fontSize?
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org