HungryMind Posted February 20, 2011 Share Posted February 20, 2011 I've this code:<input class="button tagadd" value="Add" tabindex="3" type="button">This button calls a JavaScript Function, but that JavaScript Function is hidden.Actually it calls an ajax function.This is a Wordpress Add Tag button code & there is no "id" attribute :SI want to call that hidden function to click on it.Is there any way to call that hidden function.I tried .click(); function, but it doesn't work :sPlease help Link to comment Share on other sites More sharing options...
thescientist Posted February 20, 2011 Share Posted February 20, 2011 what do you mean by a hidden function? Is the AJAX function making a server side call? Do you have a link or code? Link to comment Share on other sites More sharing options...
HungryMind Posted March 2, 2011 Author Share Posted March 2, 2011 I want to call this function without mouse click on link: Please guide. <script>$(document).ready(function(){$(".link").click(function(event){alert("As you can see, the link no longer took you to jquery.com");event.preventDefault();});});</script><div class="link">click here</div> Link to comment Share on other sites More sharing options...
thescientist Posted March 2, 2011 Share Posted March 2, 2011 try changing it to an id instead of class. the jquery syntax $('something') is meant to refer to ID (like document.getElementById), so it should look like $('#element_id) Link to comment Share on other sites More sharing options...
HungryMind Posted March 2, 2011 Author Share Posted March 2, 2011 Thanks thescientistBut the problem is that! there is no id set on div where i want to apply my code.It's a wordpress theme code.This is the code: <input class="button tagadd" value="Add" tabindex="3" type="button"> When i click on this input button, an hidden function calls, but i can't find that function.Wordpress hide that function in it's library.I Just want to click on this input button from javascript function without mouse click on this input button.But i'm sure that this input button call an ajax function.I'm pasting here some of extracted code.HTML CODE <div class="tagsdiv" id="post_tag"> <div class="jaxtag"> <div class="nojs-tags hide-if-js"> <p>Add or remove tags</p> <textarea name="tax_input[post_tag]" class="the-tags" id="tax-input[post_tag]"></textarea></div> <div class="ajaxtag hide-if-no-js"> <label class="screen-reader-text" for="new-tag-post_tag">Post Tags</label> <div class="taghint">Add new tag</div> <input id="new-tag-post_tag" name="newtag[post_tag]" class="newtag form-input-tip" size="16" autocomplete="off" value="" type="text"> <input class="button tagadd" value="Add" tabindex="3" type="button"> </div></div> <p class="howto">Separate tags with commas.</p> <div class="tagchecklist"></div></div><p class="hide-if-no-js"><a href="#titlediv" class="tagcloud-link" id="link-post_tag">Choose from the most used tags in Post Tags</a></p></div> SOME EXTRACTED JAVASCRIPT CODE var tagBox,commentsBox,editPermalink,makeSlugeditClickable,WPSetThumbnailHTML,WPSetThumbnailID,WPRemoveThumbnail;function array_unique_noempty(b){ var c=[]; jQuery.each(b,function(a,d) { d=jQuery.trim(d); if(d&&jQuery.inArray(d,c)==-1) { c.push(d) } }); return c;}(function(a){tagBox={clean:function(b){return b.replace(/\s*,\s*/g,",").replace(/,+/g,",").replace(/[,\s]+$/,"").replace(/^[,\s]+/,"")},parseTags:function(e){var h=e.id,b=h.split("-check-num-")[1],d=a(e).closest(".tagsdiv"),g=d.find(".the-tags"),c=g.val().split(","),f=[];delete c[b];a.each(c,function(i,j){j=a.trim(j);if(j){f.push(j)}});g.val(this.clean(f.join(",")));this.quickClicks(d);return false},quickClicks:function(c){var e=a(".the-tags",c),d=a(".tagchecklist",c),b;if(!e.length){return}b=e.val().split(",");d.empty();a.each(b,function(h,i){var f,g,j=a(c).attr("id");i=a.trim(i);if(!i.match(/^\s+$/)&&""!=i){ g=j+"-check-num-"+h; f='<span><a id="'+g+'" class="ntdelbutton">X</a>Â '+i+"</span> "; d.append(f); a("#"+g).click(function() { tagBox.parseTags(this); })}})},flushTags:function(e,b,g){b=b||false;var i,c=a(".the-tags",e),h=a("input.newtag",e),d;i=b?a(b).text():h.val();tagsval=c.val();d=tagsval?tagsval+","+i:i;d=this.clean(d);d=array_unique_noempty(d.split(",")).join(",");c.val(d);this.quickClicks(e);if(!b){h.val("")}if("undefined"==typeof(g)){h.focus()}return false},get:function(c){var b=c.substr(c.indexOf("-")+1);a.post(ajaxurl,{action:"get-tagcloud",tax:b},function(e,d){if(0==e||"success"!=d){e=wpAjax.broken}e=a('<p id="tagcloud-'+b+'" class="the-tagcloud">'+e+"</p>");a("a",e).click(function(){tagBox.flushTags(a(this).closest(".inside").children(".tagsdiv"),this);return false});a("#"+c).after(e)})},init:function(){var b=this,c=a("div.ajaxtag");a(".tagsdiv").each(function(){tagBox.quickClicks(this)});a("input.tagadd",c).click(function(){b.flushTags(a(this).closest(".tagsdiv"))});a("div.taghint",c).click(function(){a(this).css("visibility","hidden").siblings(".newtag").focus()});a("input.newtag",c).blur(function(){ if(this.value=="") { a(this).siblings(".taghint").css("visibility","") }}).focus(function(){ a(this).siblings(".taghint").css("visibility","hidden")}).keyup(function(d){ if(13==d.which) { tagBox.flushTags(a(this).closest(".tagsdiv")); return false; }}).keypress(function(d){ if(13==d.which){ d.preventDefault(); return false; }}).each(function(){ var d=a(this).closest("div.tagsdiv").attr("id"); a(this).suggest(ajaxurl+"?action=ajax-tag-search&tax="+d,{delay:500,minchars:2,multiple:true,multipleSep:", "})});a("#post").submit(function(){ a("div.tagsdiv").each(function() { tagBox.flushTags(this,false,1) })}); It's really a challenge for me.I simply just want to auto add my tags on input fields and then want to click on input button, then submit.I can auto set tags in input field, and can auto submit form.But i can't auto click on add tags button without mouse click on input button.Please Help. Link to comment Share on other sites More sharing options...
ShadowMage Posted March 2, 2011 Share Posted March 2, 2011 the jquery syntax $('something') is meant to refer to ID (like document.getElementById), so it should look like $('#element_id)That's not accurate. jQuery selectors use many (if not all) of the same selectors that CSS uses. $('.classname') is perfectly valid as would be $('#element_id') or even $('.classname div') Link to comment Share on other sites More sharing options...
thescientist Posted March 2, 2011 Share Posted March 2, 2011 actually, now that I look it up, the class selector should work, but perhaps you are using the wrong class name? something else to consider, which I have had more luck with, is using the bind method to attach event handlers.http://api.jquery.com/bind/so, something like this: $('.tagadd').bind('click', function() { alert("clicked");}); Link to comment Share on other sites More sharing options...
thescientist Posted March 2, 2011 Share Posted March 2, 2011 That's not accurate. jQuery selectors use many (if not all) of the same selectors that CSS uses. $('.classname') is perfectly valid as would be $('#element_id') or even $('.classname div')yup, i took that back in my follow up post. Link to comment Share on other sites More sharing options...
ShadowMage Posted March 2, 2011 Share Posted March 2, 2011 The JS you posted looks as though it has been minified, making it challenging to debug. However, this line:a("input.tagadd",c).click(function(){b.flushTags(a(this).closest(".tagsdiv"))});is definitely binding a click event to the button you posted.Are you trying to programmatically click the button? Is there more than one button with the classname 'tagadd'?If yes to the first and no to the second then this should work:$("input.tagadd").click(); Link to comment Share on other sites More sharing options...
HungryMind Posted March 2, 2011 Author Share Posted March 2, 2011 Thanks for your replies friends.Yes class name works with JQuery.And on my hand here is only 1 separate class name in whole code. So we can use it on JQuery for specific that one input button.Yes i want to click that button programmatically.JQuery Bind works OnClick.I think these are the key lines, which can solve my problem.But i can't understand that how can i use this function var d=a(this).closest("div.tagsdiv").attr("id"); a(this).suggest(ajaxurl+"?action=ajax-tag-search&tax="+d,{delay:500,minchars:2,multiple:true,multipleSep:", "}) Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.