Here's the code:
for eachP in arr14:
print('<a class="link" href="javascript:void(0);" id="{0}">{1} onclick=""</a><br />'.format(arr14.index(eachP), eachP))
Now, this code is in working state but, I want to alter the code and do something with the onclick="" attribute.
I would like to detect which link user has pressed and alerting the exact same link.
The code that I was writing was this:
onclick="<script>alert(document.getElementById(" + arr14.index(eachP) + ");)</script>"
Note: It's a .py file and I am using HTML, JS and Python(of course) inside it.
I am having problem with the onclick event. I would highly appreciate if anyone could help solve my problem ^.^
If I'm not mistaken you can do that:
onclick="someMethod(this)"
function someMethod(input) {
alert(input.id);
}
jsfiddle
Related
Probably something simple so sorry!
Currently, I have <button id="pin">Get pin</button> and it works. (there is a script later on that this calls).
But, I want it to work on some text - preferable an <a href> as the styles are set up on this - so something like Get pin - obviously this would not work so would like to know how to get it to work! :)
I am trying to get it to run the below when clicking it:
<script>
$("#pin").click(function() {
swal("Your support pin", "Your support pin is: {$support_pin}", "info")
});
</script>
Thanks
Change href to "#" and add a click listener and it should work
Get pin
I was looking to find out what version of jquery do i used based on the following script that my friend wrote for me, unfortunately he is on holiday so I can't get in touch with him.
I have added the following code within my body tag and then calling it below that:
$(document).ready(function() {
$('.top_cols_hide_arrow').click(function() {
$('.finishing_top_cols_hide').toggle("top");
});
$('.top_cols_hide_arrow').click(function(){
$(this).toggleClass('active');
});
});
and the HTML part:
<div class="finishing_top_cols_hide_arrow_mn">
<span class="finishing_top_cols_hide_arrow">open</span>
</div>
I am trying to run this on my localhost but whenever I click the arrow nothing happens and then I realised that I dont really have a script source for this to function and I'm not sure what I need to link to, in order to get this to work.
If somebody could please advise.
You can use this:
<script src="http://code.jquery.com/jquery-1.12.4.min.js"></script>
The code that your friend wrote for you is simple so most of Jquery versions will support it.
I need to create a log in popup on mouse-over on a link lust like CodeProject
Sign In link works.
In my code the log in popup is not appearing on right place and mouse over is not working properly. But I want same as the code project log in popup..
How I can achieve this..
Any suggestion is appreciated..
When I read your question, the following came to mind:
http://aext.net/2009/08/perfect-sign-in-dropdown-box-likes-twitter-with-jquery/
It "looks" similar to Code Project's solution, however behavior-wise, it does require minor modification; i.e. It triggers on 'click' instead of the hover/mouseover that you want.
Hopefully its somewhat useful.
first of all ...try this..
.loginpopup{display:none;....Your another style}
.loginpopup:hover{display:block;....Your another style}
I guess something like this will work, with jQuery of course.
<style>
#popup {
display: none;
}
</style>
<script>
$("#yourlink").mouseenter(function () {
$("#popup").show();
});
</script>
<div id="popup">Your popup</div>
<a id="yourlink" href="whatever">http...</a>
I am just curious how would anyone make this. I am trying to figure out with lack of knowledge and of course I cannot make it.
So it would be something like...
If in jquery there is declared onClick function something like "firstGateway" and "secondGateway" how can I add what if there is first and what if its second.
I can't even explain well.
But let me try.
<a onClick="firstGateway">YES FIRST!</a>
That would be html piece and jquery would need to run following:
<script type="text/javascript" src="http://fileice.net/gateway/mygate.php?id=492b542f45684b42"></script>
onClick=startGateway('123456');
and if it would be in html like this:
<a onClick="secondGateway">YES SECOND!</a>
Then jquery would run following:
<script type="text/javascript" src="http://fileice.net/gateway/mygate.php?id=4465766c4278366467523838"></script>
onClick=startGateway('654321');
Hope you understand me. I will still try to make it work but I do not think I will be able to succeed.
$('a').click(function(e){
if (e.target.innerHTML == "something")
//fooo
else
// Bar
});
You can check anything you want inside the callback. e.target is the anchor that was clicked.
if (e.target.id == "someId")
if ($(e.target).hasClass('fooClass'))
With your current code, if someone clicks on the link nothing happens. Let's fix that first of all:
This:
<a onClick="firstGateway">YES FIRST!</a>
Should be this:
<a onClick="firstGateway()">YES FIRST!</a>
If you want to execute the function firstGateway() whenever the user clicks that link. However, this is still not the best way and I'm going to show you a better way below. (Note that this better way is also needed for my final solution).
Now we turn this into:
<a id='gateway1'>YES FIRST!</a>
No longer do we define the event in the HTML, instead we do so in our javascript using jQuery:
$(document).ready(function ()
{
$('a#gateway1').click = firstGateway; // Do note: this time around there are
// no brackets
}
Using this, you can now do several things. First, you could do this:
$('a#gateway1').click();
It simulates a click on the link, which I believe does the thing you wanted to do.
However, in order to write your code, you have made sure that you knew what function you were connecting to it in your javascript, so you might not even need such a solution anymore as you should be able to do this:
$(document).ready(function ()
{
$('a#gateway1').click = firstGateway; // Do note: this time around there are
// no brackets
firstGateway();
}
Here's what's happening.
My page loads. Then jQuery loads a feed which is injected into a contentCol div...
in that feed is:
Comment
There is also:
<div class="storyItemComments" id="storyItemComments_66" style="display:none;">....
For some reason this is not working:
$(".commentWrite").live("click",function(){
cmt2open = $(this).attr('name');
$("#" + cmt2open).show();
return false;
});
Any ideas? The only thing I can think of is that it has something to do with the fact that I am using jQuery AJAX to load in the content which the LIVE statement above is referencing....
thanks
on most occasions people should use the die() function before the live... so that will clear any previews instructions and that function is only triggered once...
another thing could be that the instructions are called before the contents are retrieved from the ajax. therefore you should use .success to check if the ajax was successfully loaded and then trigger the click instructions.
as it seems that the <div id="storyItemComments_66" has not been picked up from the DOM.
Following from your comment to this answer
Can you try the following instead of show()?
$("#" + cmt2open).attr('display', 'block');
Can you place your javascript inside;
$(document).ready(function(){
//your code here
});
Not sure this will fix it but it's good practice I find.
Also have you alerted out your variables to see what you get?
What is the error you are getting if any?
Have you tried putting an alert at the top of the function to see if the click event works?
edit
let me know if the above does not fix it and I'll remove this answer to clear out the noise