working on it ...

Filters

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>
    <html>
    	<head>
    		<meta charset="utf-8">
    		<title>Test</title>
    		<script language="javascript"> 
    function toggle(elementId) {
    	var ele = document.getElementById(elementId);
    	if(ele.style.display == "block") {
        		ele.style.display = "none";
      	}
    	else {
    		ele.style.display = "block";
    	}
    } 
    </script>
    	</head>
    	<body>
    <div class="tree">
    <div>
    BLA BLA
    </div>	
    <a id="displayText" href="javascript:toggle('toggleText');">show</a> <== click Here
    <div onclick="javascript:toggle('toggleText');">
    <h1>Hello!</h1>
    <div id="toggleText" style="display:none; border-width:2px; border-style:solid">Hidden data...</div>
    </div>
    <div>
    BLA
    </div>	
    <div>
    BLA BLA 
    </div>	
    <div>
    BLA BLA 123
    </div>
    <a id="displayText" href="javascript:toggle('toggleText2');">show</a> <== click Here
    <div id="toggleText2" style="display: none" href="javascript:toggle();"><h1>Hide!</h1></div>	
    </div></body>
    </html>

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

    Event Handler onClick

     <!DOCTYPE html>
    <html lang="en">
    
    	<head>
    		<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>
    	</head>
    
    	<body>
    
    <div>Event Handlers</div>
    
    
    		<form>
    			<input type="button" value="click me" onClick="alert('Hacked!');"/>
    
    		</form>
    
    		<script>
    		//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.//
    
    
    		</script>
        </body>
    
        </html>                       

    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: post.md
    # 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:
    
    ```java
    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) {
                super(view);
                view.setOnClickListener(this);
                mTextView = (TextView) view;
            }
    
            public void setItem(String item) {
                mItem = item;
                mTextView.setText(item);
            }
    
            @Override
            public void onClick(View view) {
                Log.d(TAG, "onClick " + mItem);
            }
        }
    
        private String[] mDataset;
    
        public MyAdapter(String[] dataset) {
            mDataset = dataset;
        }
    
        @Override
        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;
        }
    
        @Override
        public void onBindViewHolder(ViewHolder holder, int position) {
            holder.setItem(mDataset[position]);
        }
    
        @Override
        public int getItemCount() {
            return mDataset.length;
        }
    }
    ```
    
    Add touch feedback to your item layout:
    
    ```xml
    <?xml version="1.0" encoding="utf-8"?>
    <TextView xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@android:id/text1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceListItemSmall"
        android:gravity="center_vertical"
        android:paddingStart="?android:attr/listPreferredItemPaddingStart"
        android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
        android:minHeight="?android:attr/listPreferredItemHeightSmall"
        android:background="?android:attr/selectableItemBackground"
    />
    ```
    
    
    

    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: ButtonListener.java
    Button aButton = (Button) findViewById(R.id.theButton); // 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"
           data-view="datatable"
           data-type="line"
           data-autoheight=1>
        <config name="onClick" fa-comment-o="{{onClick}}"></config>
        
        <div data-view="column"
             data-fillspace=1
             data-id="title">
          Title
        </div>
    
        <div data-view="column"
             data-fillspace=1
             data-id="url">
          URL
        </div>
        
    
        <div data-view="column"
             data-template="<span style='cursor:pointer; text-align:center' class='webix_icon fa-comment-o'></span>"
             data-id="discuss">
          Discuss
        </div>
    
        <ul data-view="data">
          {{#each posts}}
             {{> postItem}}
          {{/each}}
        </ul>
        
      </div>
    </template>
    
    
    

    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: http://carl.tips/1ToIB1K
    */
    
    // 1. Add Google Analytics Universal Event Tracking Snippet for 'outbound/click/url' below existing GA code snippet
      
      <script>
      var trackOutboundLink = function(url) {
         ga('send', 'event', 'outbound', 'click', url, {
           'transport': 'beacon',
           'hitCallback': function(){document.location = url;}
         });
      }
      </script>
      
    // 2. Create/Add jQuery Snippet to a .js File: Change li#menu-item-99 to your menu item and http://exampledomain.com to your external site url
      
      $("li#menu-item-99 a").attr("onclick","trackOutboundLink('http://exampledomain.com'); 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.RemoveAllListeners();
    			button.onClick.AddListener(() => OnClick(i));
    		}
    	}
    	
    	private void OnClick(int index) {
    		Debug.Log("You click button at index: " + index);
    	}
    
    }
    
    
    
    • Public Snippets
    • Channels Snippets