JavaScript Find data value from HTML find data value from percentile,find data value jquery,find

I want JQuery function to return me the value inside the 'data-tabconfig'

<li class="tab-add" data-tabconfig="#{layoutBean.maxTabs}">

I can easily get it if I call onclick function.

$(this).attr('data-tabConfig');

But I don't want to get it on click,I want to get it on bodyload().

I tried with .find() but I couldnt get it working

This was my attempt $('li').find().attr('data-tabConfig');

Answer:1
    $(document).ready(function(){

       $('li.tab-add').attr('data-tabconfig');
//OR

       $('li.tab-add').data('tabconfig');

    });
Answer:2

To get the contents of the attribute data-id (like in ) you have to use

$('li.tab-add').attr("data-tabconfig") // will return the string 123

or .data() (if you use newer jQuery >= 1.4.3)

$('li.tab-add').data("tabconfig") // will return the string 123
Answer:3

Use has attribute selector to get the element with a particular attribute. Although wrap it within document ready handler to run after elements are loaded.

$(document).ready(function(){
    var val = $('li[data-tabConfig]').attr('data-tabConfig');
    // do the rest
});
Answer:4

Try this

$(document).ready(function(){
$('.tab-add').attr('data-tabConfig');
});

Fiddle Here

Answer:5

I am using extjs 5 on web app using sencha CMD layout (mvvm) and would like to bind a store (for labels) to filter list in my view grid the viewModel store definition is: stores: { labelContacts:...

I am using extjs 5 on web app using sencha CMD layout (mvvm) and would like to bind a store (for labels) to filter list in my view grid the viewModel store definition is: stores: { labelContacts:...

I am trying to mount/unmout a Pixi stage with React (I don't want to use react-pixi yet) I have an error when I re-mount the component: Uncaught Error: Resource with name "cupCake.png" already ...

I am trying to mount/unmout a Pixi stage with React (I don't want to use react-pixi yet) I have an error when I re-mount the component: Uncaught Error: Resource with name "cupCake.png" already ...

I want to understand the best way to improve the performance of jQuery code. Actually, I know how to cache the jQuery selectors to not touch the DOM multiple times as follow: The worst way $('....

I want to understand the best way to improve the performance of jQuery code. Actually, I know how to cache the jQuery selectors to not touch the DOM multiple times as follow: The worst way $('....

I'm trying to test protractor on a vanilla.js app and when I run protractor basicConf.js I am getting below error : This webpage is not available ERR_CONNECTION_REFUSED This is my test: describe(...

I'm trying to test protractor on a vanilla.js app and when I run protractor basicConf.js I am getting below error : This webpage is not available ERR_CONNECTION_REFUSED This is my test: describe(...

  1. run protractor config file
  2. run protractor config
  3. protractor run configuration
  4. npm run protractor config file
  5. npm run protractor config