-1

I need to change the link in my div which has <div id="0"> .

My div code:

    <div id="0">
   <div id="header_color" class="spacing-top context_menu">
      <div class="row">
         <div contenteditable="true" class="col-md-12 heading-sm28">Lets get started on project.</div>
         <div contenteditable="true" class="col-md-12 smalltxt-center">Lorem Ipsum is simply dummy text of the test change link.</div>
         <div class="col-md-12 center context_menu context_link"><a href="http://google.com" target="_blank" class="btntst-back">Get in touch</a></div>
      </div>
      <div class="row">
         <div contenteditable="true" class="col-md-12 heading-sm28">Lets get started on project.</div>
         <div contenteditable="true" class="col-md-12 smalltxt-center">Lorem Ipsum is simply dummy text of the test change link.</div>
         <div class="col-md-12 center context_menu context_link"><a href="http://google.com" target="_blank" class="btntst-back">Get in touch</a></div>
      </div>
   </div>
</div>

The command I am trying to use is -

$(id).children().attr("href",'http://example.com');

Value of id I am getting is -

var id = '#'+this.selectedDivCodesub+' '+".clickedDiv";

which is - #0 .clickedDiv

I am sure I am doing something wrong while getting the id. Note that I am using clickedDiv because I am trying to change the address of the clicked link.

halfer
  • 19,824
  • 17
  • 99
  • 186
user2828442
  • 2,415
  • 7
  • 57
  • 105

2 Answers2

0

I'm not sure about this, but you can try :)

$(function(){
$('#0').click(function(){
$('.center context_menu context_link').attr("href",'http://example.com');
})
});

hope this will help :)

0

When you are getting the Id of the element you are appending a className to the Id which doesn't make sense as:

var id = '#'+this.selectedDivCodesub+' '+".clickedDiv";

the above code returns you the selector to pick the div and there is no such div with a class clickedDiv

what you need to do is, give your div a class (all the divs that may have that child) and bind a click event to it like:

<div id="0" class="someClassName">

and in your JS just attach a click event to the clicked element and add a class to the clicked element (only if there is a real need)

$( ".someClassName" ).click(function() {
  $( this ).addClass("clicked");
  $(this).children().attr("href",'http://example.com'); //not a good idea but your requirement states it

});
Zeeshan Adil
  • 1,937
  • 5
  • 23
  • 42
  • i will try this and vote, meanwhile i am looking for paid jquery support for my cms workif you have time then please ping me here - ersaurabh101@gmail.com – user2828442 Sep 03 '18 at 10:24