What happens when you click on paper-tabs in a polymer?

Struggling to get click events to fire on <paper-tabs> and <paper-tab>. Interestingly, when manually adding event listeners in Chrome's developer tools, it works fine. But the same code doesn't seem to work in my application:

// app.html
<paper-tabs selected="0" class="bottom indent" style="width: 200px;" self-end>

    <paper-tab id="one">ONE</paper-tab>
    <paper-tab id="two">TWO</paper-tab>

</paper-tabs>

// app.js
window.addEventListener('polymer-ready', function(e) {
    var tabs = {
        one: document.querySelector('#one'),
        two: document.querySelector('#two')
    };

    tabs.one.addEventListener('click', function(e) {
        console.log(e, this);
    });

    // !! This logs the expected object !!
    console.log(tabs);
}

Is there something I'm missing here? Other components like paper-slider are working correctly with event listeners, but not the tabs.

Answer №1

Success was achieved upon testing: http://jsbin.com/sohik/1/edit

Could a specific web browser be causing the issue?

It's important to note that waiting for the polymer-ready event is only required when accessing custom APIs. Otherwise, the elements themselves can be targeted and event listeners can be added without any issues.

Answer №2

Give this a shot:

$(document).on('click', 'tab-element', function() {
//your custom code here
});

No need to stress about waiting for Polymer to load before adding an event listener - simply use

$(document).on(EVENT, TYPE, FUNCTION(){CUSTOM_CODE});

Answer №3

instance

Polymer version 1.0

<dom-module id="unique-cell">
   <div class="click-me-button" on-click="greeting">
      example
   </div>
   Polymer({
        is: 'unique-cell',
        greeting: function(){
           alert("hello");
        }
</dom-module>

Answer №4

I followed these steps and the outcome was quite satisfactory!!

Within my index.html file

   <paper-tabs id="mainTab" selected="{{selectedtab}}" noink class="bottom flex" style="width= 300px;" on-iron-select="onTabSelect"> your tabs here   </paper-tabs>

Then, in my app.js file

app.onTabSelect = function(event, details){    
console.log(event.target.selected); };

That's all there is to it.

Answer №5

Here is a working example:

HTML:

<paper-tabs selected="{{tabSelected}}">
    <template is="dom-repeat" items="[[optionsArray]]">
        <paper-tab on-tap="onTabSelect">[[item.label]]</paper-tab>
    </template>
</paper-tabs>

Javascript:

onTabSelect: function(event) {
    console.log(event.model.item);
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

JavaScript or Query: Transforming an Object from an Associative Array

Can someone help me out with converting an associative array into an object in JavaScript? I tried searching on Stackoverflow but couldn't find a working example. Here is the example structure: var combinedproducts = [["Testing-1","test-1"],["Testin ...

Mongoose: An unexpected error has occurred

Recently, I developed an express app with a nested app called users using Typescript. The structure of my app.js file is as follows: ///<reference path='d.ts/DefinitelyTyped/node/node.d.ts' /> ///<reference path='d.ts/DefinitelyTyp ...

Sending CSV files to users using MEANJS

Currently, I am employing the MEANJS framework to create a Node.js application. Essentially, I have JSON data stored in MongoDB and I am utilizing the json-csv NPM module to convert it into a CSV format. I managed to successfully download the CSV file loc ...

Detecting changes in input elements when setting values in AngularJS

Access Code: http://jsfiddle.net/mb98y/309/ HTML <div ng-app="myDirective" ng-controller="x"> <input id="angular" type="text" ng-model="data.test" my-directive> </div> <button onclick="document.querySelector('#angular&a ...

Creating JavaScript classes based on JSON schemas

I have a JSON file containing information and data related to my work, presented in the following format: { "Employees":[ { "id": 1, "fullName": "Test Test" } ], "Infos":[ { "id": 1, ...

Tips for managing and loading data into a dataGrid or table with the help of ReactJS and ReactHooks

Struggling to retrieve user input data from the form and display it in the table/Datagrid below, without success. Follow the process flow outlined below Once the user submits the form and clicks the send now button, the {handleSubmit} function is trigger ...

Steps for implementing a single proxy in JavaScript AJAX with SOAP, mirroring the functionality of the WCF Test Client

I am working with a WCF web Service and a javascript client that connects to this service via AJAX using SOAP 1.2. My goal is to pass a parameter to instruct the AJAX SOAP call to use only one proxy, similar to how it is done in the WCF Test Client by unch ...

Trigger an Ajax function using a button within a Bootstrap modal

I need to trigger an ajax function after selecting an option from a bootstrap confirmation modal. The modal will appear by calling the remove(parameter) function. Any assistance would be greatly appreciated function remove(parameter){ // $("#remove-mod ...

What causes the selected option to be hidden in React?

I created a basic form demo using react material, featuring only one select field. I followed this link to set up the select options: https://material-ui.com/demos/selects/ With the help of the API, I managed to display the label at the top (by using shri ...

Surprise mistake: Jade's error with the length

What can I do to address this problem? The jade file in question is as follows: extends layout block content h1. User List ul each user, i in userlist li a(href="mailto:#{user.email}")= user.username U ...

Upon selecting a checkbox, I desire for a corresponding checkbox to also be marked

I am looking to enhance my current project by incorporating a feature that allows the user to simply check a checkbox with specific content once. For example, I have a recipes page where users can select ingredients they need for each recipe while planning ...

Execute a jQuery function every time the class of the parent container div changes

I am seeking to trigger the function below whenever its containing div parent <div class="section">...</div> transitions to an "active" state, for example: <div class="section active">...</div> $(".skills-grid__col").each(function ...

Leveraging the power of ES6 syntax in Node scripts with Babel

My npm CLI tool utilizes ES6 syntax from BabelJS, specifically arrow functions. Within the entry point of my tool, I'm using the following require: require('babel-core/register'); var program = require('./modules/program.js'); I ...

Watcher doesn't detect modifications in array values

I am working with a basic array structure that looks like this: dates[2] 0:"2018-01-09T15:00:00.000Z" 1:"2018-01-10T14:00:00.000Z" My watcher is configured as follows: data() { return { dates: [], } } watch: { // this fu ...

Learn the process of extracting an array of objects by utilizing an interface

Working with an array of objects containing a large amount of data can be challenging. Here's an example dataset with multiple key-value pairs: [{ "id": 1, "name":"name1", age: 11, "skl": {"name": & ...

Updating the value of a localStorage key after each successful AJAX call in JavaScript

I'm currently facing a challenge with my local storage key value. The issue is that it doesn't update the value when the AJAX call successfully returns data. It only retains the old stored data, requiring me to manually refresh the page by pressi ...

How to Implement Multi Select Drag and Drop Feature in Angular 4?

Currently, I am implementing Angular 2 Drag-and-Drop from this library to enable the selection of list items using a drag and drop method. However, I have encountered issues with its functionality on touch devices and when attempting to perform multiple it ...

Fastify endpoint failing to respond to designated URL

Within my code, there is a router setup: fastify.get('/:link', (req, reply) => { req.params.url = req.host+req.url; reply.view("template.ejs",req.params); }); I am trying to capture URLs and process them in the template. All URLs are ...

Troubleshooting VueJS's Dilemma with Quotation Marks

When I try to parse a string containing either double quotes or single quotes, an error is being thrown: JSON Unexpected token. Is there a way to properly parse and bind it to a variable in Vue.js? PHP $arr = array(); $arr[0]['description'] = ...

Grids designed in the style of Pinterest

Seeking advice on aligning divs in a Pinterest-style layout. Currently, my setup looks like this: https://i.sstatic.net/erlho.png But I want it to look more like this: https://i.sstatic.net/K9FnD.png Would greatly appreciate any tips or suggestions on ho ...