I’m using jQuery Tag-It! in my project.
I want to make my object’s border visible when the onfocus event fires, but I can’t make it work.
My code:
<ul id="TagsDesc" name="nameOfSelect" runat="server" ></ul>
<script type="text/javascript">
$(document).ready(function () {
$('#<%=TagsDesc.ClientID %>').focus(function () {
$(this).css("border", "1px solid");
});
$('#<%=TagsDesc.ClientID %>').tagit({
'maxTags': 10,'minLength': 1,
'maxLength': 12,
'tagsChanged': showTags
});
function showTags() {
var tags = $('#<%=TagsDesc.ClientID %>').tagit("tags");
var tagsContainer = $('#<%=tagsContainer.ClientID %>');
var res = '';
for (var i in tags)
res += ',' + tags[i].value;
tagsContainer.val(res);
}
});
</script>
Any idea please?
The focus event is actually applicable to focusable elements only. (
<input>,<select>, etc.)ulorliare not focusable by default.One work around is to use
tabidexon the element you want to make focusable, not sure if its completely cross browser. Adding atabindexmakes most elements focusable as it forces to be focused by keboard.For setting css values you can use
:focuspseudo seleector rather than using jquery.Specific answer for tagit:
apply
focusevent on input with classui-widget-content ui-autocomplete-inputand change border of the parent element with classestagit ui-widget ui-widget-content ui-corner-all