Link to home
Start Free TrialLog in
Avatar of cofactor
cofactor

asked on

How to focus on the clicked <a> tag ?

Here is my JQuery code

<script type="text/javascript" src="jquery-1.4.2.min.js"> </script>
<script type="text/javascript">
            $(document).ready(function()
            {
                  $("a").bind("click", function(){
                  


                          var param=$(this).attr("id");
                    
                        $("."+param).each(function()
                        {
                              this.click();
                              
                        });
                        }
                  );                  
            });
            
</script>


Now, I wish  to keep the focus on the clicked  <a>  tag . What to modify in this code ?
ASKER CERTIFIED SOLUTION
Avatar of Gurvinder Pal Singh
Gurvinder Pal Singh
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of cofactor
cofactor

ASKER

added focus();      in the code.

Still Not working .

Here is the modified code:


<script type="text/javascript" src="jquery-1.4.2.min.js"> </script>
<script type="text/javascript">
            $(document).ready(function()
            {
                  $("a").bind("click", function(){
                  


                    var param=$(this).attr("id");
                    
                      $("#"+param).focus();

                        $("."+param).each(function()
                        {
                              this.click();
                              
                        });
                        }
                  );                  
            });
            
</script>
could you confirm the object with the class like ("."+param). are not anchor ?
Else seems you call infinitely  $("a").bind("click again and again
>>>could you confirm the object with the class like ("."+param). are not anchor ?

yes. they are not anchors . they are checkboxes.

>>>Else seems you call infinitely  $("a").bind("click again and again.

not infinitely . I  have finite checkboxes with the same class values .

For your information ,  the id of the anchor tag  is same as the class value of the finite number of checkboxes.

So, when I click the anchor, all those checkboxes whose class value is same as the id value of the anchor are also clicked.

This is a working code.

Now,I want to add the focus on the clicked anchor. how to do that ?
comments please.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Seems you want soimething like this :


<html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.4.2.min.js"> </script>
<script type="text/javascript">
	$(document).ready(function() {
		$("a").bind("click", function(e){
			e.preventDefault(); // remove this line it if your want to go Google at the end
			alert("fire myself");
			var CheckboxToClick = $(this).attr("value");
			$(this).focus();
			$("."+CheckboxToClick).each(function() {
				$(this).attr("checked", true);
			});
		});                  
	});
</script>
</head>
<body>
<a href="http://www.google.com" class="myself" id="myself" value="CheckboxToClick" >Click on me to check the boxes!</a>
<input id="cb0" type="checkbox" class="CheckboxToClick" />
<input id="cb1" type="checkbox" class="DontCheckMe" />
<input id="cb2" type="checkbox" class="CheckboxToClick" />
</body>
</html>

Open in new window