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 ?
<script type="text/javascript" src="jquery-1.4.2.min.js">
<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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
could you confirm the object with the class like ("."+param). are not anchor ?
Else seems you call infinitely $("a").bind("click again and again
Else seems you call infinitely $("a").bind("click again and again
ASKER
>>>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 ?
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 ?
ASKER
comments please.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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>
ASKER
Still Not working .
Here is the modified code:
<script type="text/javascript" src="jquery-1.4.2.min.js">
<script type="text/javascript">
$(document).ready(function
{
$("a").bind("click", function(){
var param=$(this).attr("id");
$("#"+param).focus();
$("."+param).each(function
{
this.click();
});
}
);
});
</script>