JQuery use variable by name of divID

0 votes

Just a quick question, that I cannot fathom out, hope you guys and girls can help.

I have a div (with ID) that when clicked opens a new div - great works well, what I really want is to "populate" the new div with predefined text based on the clicked div's ID. example:

<div class="infobox" id="help_msg1">Click me</div>

I may have say 3 (actually more but...) of these div's

This opens:

<div id="helpbox">text in here</div>

In/on my .js page I have doc ready etc then:

var help_msg1 ='text that is a help message'; var help_msg2 ='text that is another help message'; var help_msg3 ='text that is yet another help message';

Then

$('.infobox').live('click',function() {
 $('#helpbox').remove();
 $('label').css({'font-weight': '400'});
 $(this).next('label').css({'font-weight': '900'});
 var offset = $(this).next().next().offset();
 var offsetby = $(this).next().next().width();
 var leftitby = offset.left+offsetby+10;

$('body').append('text in here'); $('#helpbox').css( { 'left': leftitby, 'top': offset.top } ); });

Note I remove each #helpbox before appending the new one and the .next().next() identifies the appropriate text input that lot all works.

What I need is how do I put var help_msg1 into the append when id="help_msg1" is clicked or var help_msg2 when id="help_msg2" is clicked etc. I have tried

Jul 19, 2022 in Web Development by gaurav
• 23,260 points
1,077 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In Web Development

0 votes
1 answer

JQuery - Change event using element by name

How to trigger a event with event ...READ MORE

answered Jun 28, 2022 in Web Development by rajatha
• 7,680 points
3,009 views
0 votes
1 answer

Why use jQuery on() instead of click()

The . on() method attaches event handlers to ...READ MORE

answered Jun 27, 2022 in Web Development by rajatha
• 7,680 points
454 views
0 votes
0 answers

how can i get the url of the content( home.html) in adress bar by jquery load() function?

I am using jquery load() function to ...READ MORE

Jul 28, 2022 in Web Development by gaurav
• 23,260 points
614 views
0 votes
1 answer

Why use jQuery on() instead of click()

on() differs from . click() in that it ...READ MORE

answered Aug 1, 2022 in Web Development by rajatha
• 7,680 points
1,390 views
0 votes
0 answers

jQuery (Greasemonkey) : Sorting images by name/class

Here is code from HTML. I would ...READ MORE

Aug 19, 2022 in Web Development by gaurav
• 23,260 points
354 views
0 votes
1 answer

What does cors means in Angularjs and what the use of it?

CORS is Cross Origin Resource Sharing which means you ...READ MORE

answered Jan 29, 2020 in Web Development by kartik
• 37,520 points
4,325 views
0 votes
1 answer

Jquery - Using .each() with variables and an IF statement

To get values from elements, you need ...READ MORE

answered Jun 21, 2022 in JQuery by rajatha
• 7,680 points
3,361 views
0 votes
0 answers

jQuery + JSON how to define key from variable

I have the following code $.post( ...READ MORE

Jul 28, 2022 in Web Development by gaurav
• 23,260 points
514 views
0 votes
1 answer

How can we set environment variables from java?

For setting the environment variable, you can ...READ MORE

answered Jun 21, 2018 in Java by Akrati
• 960 points
3,860 views
0 votes
2 answers

difference between class and instance attributes

Apart from the performance, there is a ...READ MORE

answered Sep 17, 2018 in Python by SDeb
• 13,300 points
902 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP