working on it ...


Explore Public Snippets

Sort by

Found 180 snippets matching: onclick

    public by lbottaro modified Jan 8, 2014  87838  462  8  8

    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  2263  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  496  8  5  1

    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  309261  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  271  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 Adam Kolinski modified Oct 10, 2016  114  0  2  0

    Placeholder image for video with button onclick load iframe. You can switch this around between youtube and vimeo or any other thirdparty video player.

    Placeholder image for video with button onclick load iframe. You can switch this around between youtube and vimeo or any other thirdparty video player.: responsive-video.html
    .video-background-landing {
        position: relative;
        cursor: pointer;
    .watch-video-button-landing {
        position: absolute;
        top: 70%;
        left: 50%;
        margin-top: -30px;
        margin-left: -80px;
        z-index: 9;
        padding: 10px 20px;
    <div class="col-sm-12 col-md-10 col-lg-10">
        <div class="video-background-landing" data-vimeoid="186219543">
            <img class="img img-responsive" src="/assets/images/dest/academy/intro-screenshot.jpg" alt="" />
            <span class="btn btn-primary-rev watch-video-button-landing">WATCH VIDEO <i class="fa fa-chevron-circle-right min-padding-all"></i></span>
      $(this).parent().html('<div class="embed-responsive embed-responsive-4by3"><iframe class="embed-responsive-item" src="'+$(this).data('vimeoid')+'?portrait=0&title=0&color=bf1f48&badge=0&byline=0&autoplay=1" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe></div>');
    • Public Snippets
    • Channels Snippets