PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, October 24, 2022

[FIXED] how to select option by default in a href

 October 24, 2022     javascript, jquery, woocommerce, wordpress     No comments   

Issue

<a href="#" class="image-swatch no-lightbox" data-value="red-1" </span>"> 
<a href="#" class="image-swatch no-lightbox" data-value="green-2" </span>">

i tried to add this but didn't work with a href

$(document).ready(function(){
    $('.image-swatch').prop('selectedIndex', 1);
});

image swatch is plugin for wordpress and have no selected by default option and my only way to do so by adding jquery so how i can select red by default using jQuery im not good when its come to coding thanks for your help


Solution

Try this, just change the index in $colores[0], 0 is equal to the first element 1 the second and so on

jQuery(document).ready(function($){
  $colores = $('.image-swatch');
  $($colores[0]).addClass('selected');
});


Answered By - Jairo Py
Answer Checked By - Mary Flores (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing