Javascript click button start with name [duplicate] - javascript

This question already has answers here:
jQuery selector for id starts with specific text [duplicate]
(4 answers)
Closed 5 years ago.
can i change this button click
$('input[name="submit.one-click-premium-de.x"]').click().first();
to a button that has a wild card after first words?
$('input[name="submit.one-click*"]').click().first();
or something?
When the Button Name start with submit.one-click i will click this.
All things after "one-click" is okay. So i want like a wildcard there...
My click on top works but i want to have a start with one-click button...
I tried much strange things but thats not working

^= is the startsWith selector:
$('input[name^="submit.one-click"]').click().first();
https://api.jquery.com/attribute-starts-with-selector/

You can use ^= to do this. It works this way:
$('input[name^="submit.one-click"]').click().first();

Related

jQuery if statement selecting an Id [duplicate]

This question already has answers here:
Is there an "exists" function for jQuery?
(47 answers)
Closed 5 years ago.
Thanks in advance,
I'm trying to create an if statement that will help me solve an issue.
I want to be able to assign an ID for a button and if that ID matches the
"if statement id entered" it will run my script else it wont do nothing.
i'v tried couple of things, but with no luck, I'm new to jQuery hope someone could give a hint,any other suggestion will be great ,cheers.
this is the script I want to run:
jQuery("#myId").append("<i class='fa fa-camera-retro fa-lg'></i>");
this is what iv tried:
if($('a' == '#myId') {
jQuery("#myId").append("<i class='fa fa-camera-retro fa-lg'></i>");
}
​
thanks to all
Since I don't know when you would like to fire that piece of code: if you are trying to trigger it after an event being dispatched you can Simply use the .on() function to attach the event listener to the element. If you are Just iterating over an element list you can use the .is() function, and check if that $('a').is('#thatID') !

How to Run two JS functions on one Click? [duplicate]

This question already has answers here:
How to call multiple JavaScript functions in onclick event?
(14 answers)
Closed 7 years ago.
I was trying to run two JS functions in one click using this. Can anybody show me how to do it correctly?
<button onclick="getlocation" onclick="showDiv()">Try It</button>
I tried adding a ; between the two functions but it didnt work too.
"Adding ";" semicolon didn't work, if you could help.."
It works for sure, you have to do it like that: onclick="getLocation();showDiv()"
Was not relevant in this case:
The problem could be, that both functions are setting the content of your div, so the second function will overwrite the content!
Use .innerHTML += "..."; on you second function, this will append the content to the exisitng content.

how to visit my site by .xyz.com/#divname, can any one help me? [duplicate]

This question already has answers here:
How to scroll an HTML page to a given anchor
(17 answers)
Closed 8 years ago.
I want browse directly to my site div by this way:
www.xyz.com/#divname
some sites I saw , I know there is a way to do it ,can anyone tell me the code
I have tried
window.location.href=#divname
but not scrolling.
Try
window.location.hash = '#divname';
Where #divname is the id of your div
Can you try this,
<body onload="window.location.hash = '#divname';">
That is called bookmark links, see here http://www.hyperlinkcode.com/bookmark.php.
To navigate to an anchor via javascript you can use this code:
window.location.hash = "#divname";
This topic is also a duplicate of the following:
How to scroll HTML page to given anchor using jQuery or Javascript?
Regards.
If you want to browse directly using a URL (as per your question), then there is absolutely no need for any javascript.
All you need to do is set an id for your div elements, that match the anchor tag you want to use. In the case of your example:
www.xyz.com/#divname
Then you would need an element like so:
<div id="divname">
</div>
Here is a working example

Only one jQuery event runs per refresh [duplicate]

This question already has answers here:
Find currently visible div in jquery
(5 answers)
Closed 3 years ago.
Only one jQuery event runs per refresh of the page. What am I doing that's so wrong?
$("#contact_link_email").on("click",function(){
$("#contact-form").replaceWith('<h2>Email heading</h2>');
});
$("#contact_link_facebook").on("click",function(){
$("#contact-form").replaceWith('<h2>Facebook heading</h2>');
});
$("#contact_link_twitter").click(function(){
$("#contact-form").replaceWith('<h2>Twitter heading</h2>');
});
$("#contact_link_gplus").click(function(){
$("#contact-form").replaceWith('<h2>GPlus heading</h2>');
});
Once one of those events runs, $("#contact-form") doesn't reference anything. If you want to replace it with something, try making that something have the same id.

how to change a button text in jQuery mobile [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
change text on button using jquery mobile.
I need to change a button text, I am using jQuery mobile.
Here is my html:
<fieldset>
<div><button type="submit" id="login_var">Login</button></div>
<div><button type="reset" >Reset</button></div>
</fieldset>
I have tried all of the examples on this page:
LINK and nothing is working for me.
Please help
I've had to do the same thing before, it's really not as obvious to do as it should be. Since jQM adds span tags inside your button, you need to change the value inside the span:
$("#login_var .ui-btn-text").text("NewText");
Similarly, if you wanted to change the icon, you could do:
$("#login_var .ui-icon").removeClass("ui-icon-arrow-l").addClass("ui-icon-arrow-r");
Edit:
Sorry I just noticed the link you posted in the question has the same solution, and you said that doesn't work for you. Maybe if you changed your buttons to
<a data-role="button"></a>
Instead of <button></button>?
Yeah you can use
$(function(){
$('#login_var').text('Ok').button('refresh');
});
As per http://jquerymobile.com/test/docs/buttons/buttons-methods.html, there are only three methods you can call on a button.

Categories

Resources