Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • Aug 17 09:32
    User @bjorno43 unbanned @linkin-park
  • Jun 20 21:19
    @bjorno43 banned @shenerd140
  • Apr 25 17:13
    @mstellaluna banned @cmal
  • Jan 08 22:05
    @mstellaluna banned @dertiuss323
  • Nov 07 2018 04:42
    User @texas2010 unbanned @ows-ali
  • Nov 02 2018 16:25
    @texas2010 banned @ows-ali
  • Oct 12 2018 05:50
    @bjorno43 banned @NACH74
  • Oct 05 2018 23:02
    @mstellaluna banned @JomoPipi
  • Sep 16 2018 12:21
    @bjorno43 banned @yash-kedia
  • Sep 16 2018 12:16
    @bjorno43 banned @vnikifirov
  • Sep 05 2018 08:12
    User @bjorno43 unbanned @androuino
  • Sep 05 2018 07:38
    @bjorno43 banned @androuino
  • Aug 23 2018 16:57
    User @bjorno43 unbanned @rahuldkjain
  • Aug 23 2018 16:23
    @bjorno43 banned @rahuldkjain
  • Jul 29 2018 14:13
    User @bjorno43 unbanned @jkyereh
  • Jul 29 2018 01:00
    @bjorno43 banned @jkyereh
  • Jul 10 2018 22:09
    @bjorno43 banned @manafn
  • Jul 06 2018 15:20
    @texas2010 banned @imlegend19
  • Jul 03 2018 12:28
    @bjorno43 banned @vbvmatta
  • Jun 29 2018 13:54
    @bjorno43 banned @OGTechnoBoy
Mark Kubik
@KUBIX90
terribly
a27-suryansh
@a27-suryansh
can anyone help me with jquery? i have a small problem
Matej Bošnjak
@mbosnjak01
post question
a27-suryansh
@a27-suryansh
@mbosnjak01 the thing is i am adding class to image element dynamically using jquery on click event and in the inspector it changes the class to "changed" however when i target the the element using .changed it is unable to find it
Matej Bošnjak
@mbosnjak01
post code as well
:)
a27-suryansh
@a27-suryansh
sure
~~~
 <script type="text/javascript">
     $(document).ready(function() {

$(".clk_london_map2").on("click", function() {
$(".clk_london_map1").attr("src", "images/london_map2.png");
$(".clk_london_map2").attr("src", "images/london_map.png");
$(".clk_london_map2").attr("id", "clk_london_map2_changed");
});


     $("#clk_london_map2_changed").on("click", function() {

$("#clk_london_map2_changed").attr("src", "images/london_map2.png");

});

     });
```
Second click function is not working only god knows why
 $("#clk_london_map2_changed").on("click", function() {

$("#clk_london_map2_changed").attr("src", "images/london_map2.png");

});
Matej Bošnjak
@mbosnjak01
would need whole code, you got codepen?
a27-suryansh
@a27-suryansh
no
i have only this code for jquery
Stephen James
@sjames1958gm
@a27-suryansh $("#clk_london_map2_changed").on("click", function() { this code is likely running before the code above it so the id is not yet assigned to the element
@a27-suryansh Why not put that code at the bottom inside the .ready function?
a27-suryansh
@a27-suryansh
@sjames1958gm it is already under that
Stephen James
@sjames1958gm
@a27-suryansh Oops - never mind - it is there already - forget all I said
a27-suryansh
@a27-suryansh
@sjames1958gm i have heard that we cannot target elements with dynamically added classes is that right?
Stephen James
@sjames1958gm
@a27-suryansh I doubt that is the case, but there might be some timing issue.
Why are you targetting an element with #clk_london_map2_changed when you can already target it with ".clk_london_map2"
Unless this is some sort of experiment?
a27-suryansh
@a27-suryansh
no actually there are images of map in the web page and when user clicks on map2 then both maps should interchange that's why @sjames1958gm
@sjames1958gm there are only 2 maps
Stephen James
@sjames1958gm
@a27-suryansh Dang I should look closer did not see the 1 and the 2
a27-suryansh
@a27-suryansh
It interchanges one time but fails to interchange second time coz you know second click function is not working @sjames1958gm
Stephen James
@sjames1958gm
@a27-suryansh You cannot target a element when the id is added later. After you add the id to the element, then you can target it
a27-suryansh
@a27-suryansh
@sjames1958gm as you can see in my code i am first changing the class only then i am targeting it on the next click event
```
$(".clk_london_map2").on("click", function() {
this changes the id @sjames1958gm
i cant figure out what i am doing wrong @sjames1958gm
Stephen James
@sjames1958gm
@a27-suryansh
$("#clk_london_map2_changed").on("click", function() {
This code runs on page ready, before you have ever clicked and run the code above it.
You cannot reference an ID that is assigned later
a27-suryansh
@a27-suryansh
ok got it @sjames1958gm
Stephen James
@sjames1958gm
@a27-suryansh :+1:
a27-suryansh
@a27-suryansh
@sjames1958gm i think this code should be placed under the first click event right?
Damn @sjames1958gm
@sjames1958gm Works like a charm!
Stephen James
@sjames1958gm
:+1:
Timing is everything :)
a27-suryansh
@a27-suryansh
@sjames1958gm may god bless you i was stuck at it for hours
Markus Kiili
@Masd925
@a27-suryansh Don't insult him. HE is the one who blesses others here.
a27-suryansh
@a27-suryansh
@Masd925 he just blessed me that's why i asking god to bless him
Markus Kiili
@Masd925
@a27-suryansh He is the brownie god, so that is why it insults him.
a27-suryansh
@a27-suryansh
you mean to say even god can't bless him now @Masd925
Markus Kiili
@Masd925
@a27-suryansh It depends on how many brownies that god in questions has.
a27-suryansh
@a27-suryansh
infinite @Masd925
Markus Kiili
@Masd925
@a27-suryansh That is hard to swallow. Are we assuming that string theory holds?
Stephen James
@sjames1958gm
@a27-suryansh You're welcome.
a27-suryansh
@a27-suryansh
@Masd925 i am not aware of that theory but seems interesting
@sjames1958gm i have made a codepen for that issue and putting the click code under that has created new issue - https://codepen.io/anon/pen/KoRBWp please have a look at it