working on it ...


Explore Public Snippets

Sort by

Found 189 snippets matching: onclick

    public by lbottaro modified Jan 8, 2014  86387  279  8  9

    How to collapse a div in html

    This code shows how to collapse a div using a simple Javascript method. The div display option toggles between 'none' and 'block', hiding or showing its content. In the example you can collapse the div clicking both on a link or on a div, using the onclick event.
    <!doctype html>
    		<meta charset="utf-8">
    		<script language="javascript"> 
    function toggle(elementId) {
    	var ele = document.getElementById(elementId);
    	if( == "block") {
 = "none";
    	else { = "block";
    <div class="tree">
    <a id="displayText" href="javascript:toggle('toggleText');">show</a> <== click Here
    <div onclick="javascript:toggle('toggleText');">
    <div id="toggleText" style="display:none; border-width:2px; border-style:solid">Hidden data...</div>
    BLA BLA 
    BLA BLA 123
    <a id="displayText" href="javascript:toggle('toggleText2');">show</a> <== click Here
    <div id="toggleText2" style="display: none" href="javascript:toggle();"><h1>Hide!</h1></div>	

    public by LaurenceTamatea modified Aug 10, 2016  2131  0  4  0

    Event Handler onClick

     <!DOCTYPE html>
    <html lang="en">
    		<title>STANDARD TEMPLATE</title>
    		<meta charset="utf-8">
    		<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
    		<style> </style>
    <div>Event Handlers</div>
    			<input type="button" value="click me" onClick="alert('Hacked!');"/>
    		//end the js statment with a semi-colon//
    		//double quotation markets for attributes and single for JS//
    		//don't need to put the script between the script tags.//

    public by szmerek modified Sep 6, 2017  281  4  5  0

    OnClick without setting an attribute of the link

    //<div id="dog" >Woow woow</div>
        (function() {
            document.getElementById("dog").onclick = function() { 
                alert('fuf fuf'); 

    external by Grantland Chew modified Jul 3, 2014  309206  2  4  0

    RecyclerView item onClick

    RecyclerView item onClick:
    # RecyclerView item onClick
    `RecyclerView` does not have an OnItemClickListener like it's predecessor, `ListView`. However, detecting item clicks is pretty simple.
    Set an `OnClickListener` in your `ViewHolder` creation:
    private static class MyAdapter extends RecyclerView.Adapter<MyAdapter.ViewHolder>  {
        public static class ViewHolder extends RecyclerView.ViewHolder
                implements View.OnClickListener {
            private String mItem;
            private TextView mTextView;
            public ViewHolder(View view) {
                mTextView = (TextView) view;
            public void setItem(String item) {
                mItem = item;
            public void onClick(View view) {
                Log.d(TAG, "onClick " + mItem);
        private String[] mDataset;
        public MyAdapter(String[] dataset) {
            mDataset = dataset;
        public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
            View v = LayoutInflater.from(parent.getContext())
                    .inflate(R.layout.list_item, parent, false);
            ViewHolder vh = new ViewHolder(v);
            return vh;
        public void onBindViewHolder(ViewHolder holder, int position) {
        public int getItemCount() {
            return mDataset.length;
    Add touch feedback to your item layout:
    <?xml version="1.0" encoding="utf-8"?>
    <TextView xmlns:android=""

    external by Stefan Kuntz modified Dec 31, 2015  262  0  3  0

    Image Alt text onclick (requires jQuery)

    Image Alt text onclick (requires jQuery): imageAltText.js
    $('img').after(function() {return "<p><code>"+$(this).attr('alt') + "</code></p>"})

    external by Tobias Straub modified Nov 22, 2014  23  1  1  0

    Android: OnClickListener for Button onClick event

    Android: OnClickListener for Button onClick event:
    Button aButton = (Button) findViewById(; // Id of the Button in the Activity layout
    aButton.setOnClickListener(new OnClickListener() {
    	@Override // Override from OnClickListener class
    	public void onClick(View v) {
    		// TODO: What should happen when the button is clicked?

    external by bartonhammond modified Sep 30, 2015  267  0  3  0

    Meteor Webix Datatable onClick event. posts_list.html has column w/ 'fa-comment-o' icon. datatable has <config> with 'onClick' and function provided by helper

    Meteor Webix Datatable onClick event. posts_list.html has column w/ 'fa-comment-o' icon. datatable has with 'onClick' and function provided by helper: posts_list.html
    <template name="postslist">
      <div data-id="postslist"
        <config name="onClick" fa-comment-o="{{onClick}}"></config>
        <div data-view="column"
        <div data-view="column"
        <div data-view="column"
             data-template="<span style='cursor:pointer; text-align:center' class='webix_icon fa-comment-o'></span>"
        <ul data-view="data">
          {{#each posts}}
             {{> postItem}}

    external by Carl Parker modified Mar 2, 2016  171  0  2  0

    Add Google Analytics Universal Event OnClick for WordPress Custom Menu Item

    Add Google Analytics Universal Event OnClick for WordPress Custom Menu Item: gistfile1.txt
     * Add Analytics Event OnClick for WordPress Custom Menu Item
     * Tutorial Link:
    // 1. Add Google Analytics Universal Event Tracking Snippet for 'outbound/click/url' below existing GA code snippet
      var trackOutboundLink = function(url) {
         ga('send', 'event', 'outbound', 'click', url, {
           'transport': 'beacon',
           'hitCallback': function(){document.location = url;}
    // 2. Create/Add jQuery Snippet to a .js File: Change li#menu-item-99 to your menu item and to your external site url
      $("li#menu-item-99 a").attr("onclick","trackOutboundLink(''); return false;");

    external by Don modified Sep 24, 2015  137  0  2  0

    passing params in javascript input onclick function

    passing params in javascript input onclick function: Javascript_onclick_passing_params.js
    "<a href='#' onclick='test(\""+elem[i].url+"\")'>dd</a><br><br>"

    external by rutcreate modified May 20, 2015  125  0  2  0

    Unity3D: Best way to add listener programmatically for Button onClick

    Unity3D: Best way to add listener programmatically for Button onClick: MyButton.cs
    using UnityEngine;
    public class MyButton {
    	public Button[] buttons;
    	private void Start() {
    		for (int i = 0; i < buttons.Length; i++) {
    			Button button = buttons[i];
    			button.onClick.AddListener(() => OnClick(i));
    	private void OnClick(int index) {
    		Debug.Log("You click button at index: " + index);
    • Public Snippets
    • Channels Snippets