JavaScript Extract css and match with data-attribute extract match from regex,extract match from regex python,extract

I have the following scenario:

<body class="theme-blue nav-black">
  <a target='_blank' href="#" data-class="theme-blue">Blue theme </a>
  <a target='_blank' href="#" data-class="nav-black">Dark Nav</a>
  <a target='_blank' href="#" data-class="nav-white">Light Nav</a>
</body>

Trying to write a script to match the classes from and for each matching 'data-class' to add a class "active" to the element;

Whats the best way to go about doing this?

So the result should look like:

<body class="theme-blue nav-black">
  <a target='_blank' href="#" data-class="theme-blue" class="active">Blue theme </a>
  <a target='_blank' href="#" data-class="nav-black" class="active">Dark Nav</a>
  <a target='_blank' href="#" data-class="nav-white">Light Nav</a>
</body>
Answer:1

You can loop each a element and then use hasClass() to check if body has the same class and if it does use addClass()

$('a').each(function() {
  if ($('body').hasClass($(this).data('class'))) {
    $(this).addClass('active')
  }
})
.active {
  background: red;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<body class="theme-blue nav-black">
  <a target='_blank' href="#" data-class="theme-blue">Blue theme </a>
  <a target='_blank' href="#" data-class="nav-black">Dark Nav</a>
  <a target='_blank' href="#" data-class="nav-white">Light Nav</a>
</body>
Answer:2

I'm stuck in the situation where my child component (autocomplete) needs to update a value of its parent (Curve), And the parent needs to update the one of the child (or to completely re-render when a ...

I'm stuck in the situation where my child component (autocomplete) needs to update a value of its parent (Curve), And the parent needs to update the one of the child (or to completely re-render when a ...

I have written following jQuery for calculating age when user selects date from date picker and the focus of textbox(#dobfield) is lost then the calculated age should get displayed on textbox (#age). ...

I have written following jQuery for calculating age when user selects date from date picker and the focus of textbox(#dobfield) is lost then the calculated age should get displayed on textbox (#age). ...

  1. display selected date in datepicker
  2. display selected date from calendar into textbox
  3. display selected date in textbox in asp.net
  4. display selected date in jquery
  5. power bi display selected date range
  6. jquery datepicker display selected date
  7. show selected date in datepicker
  8. how to show selected date in datepicker
  9. selected date in jquery datepicker
  10. selected date in datepicker

I am trying do cache busting using webpack by adding a hash to the end of each javascript file. My webpack configuration file is below: const AssetsPlugin = require('assets-webpack-plugin'); const ...

I am trying do cache busting using webpack by adding a hash to the end of each javascript file. My webpack configuration file is below: const AssetsPlugin = require('assets-webpack-plugin'); const ...

  1. webpack cache busting index.html
  2. webpack cache busting css
  3. webpack cache busting images
  4. webpack cache busting
  5. webpack cache busting js
  6. cache busting webpack
  7. webpack 4 cache busting
  8. react webpack cache busting
  9. webpack bundle cache busting
  10. webpack chunk cache busting
  11. angular webpack cache busting
  12. laravel webpack cache busting
  13. webpack disable cache busting
  14. vue webpack cache busting
  15. webpack html cache busting
  16. webpack 2 cache busting
  17. wordpress webpack cache busting
  18. webpack dynamic import cache busting
  19. angular cli webpack cache busting
  20. html-webpack-plugin cache busting

I updated the ui-bootstrap version from 0.13.0 to 0.13.4, It broke the validation on datepicker field. Plunkr with a problem Previously I was using 0.13.0 and it was working fine. Basically when I ...

I updated the ui-bootstrap version from 0.13.0 to 0.13.4, It broke the validation on datepicker field. Plunkr with a problem Previously I was using 0.13.0 and it was working fine. Basically when I ...