Change the text value in jquery object

for(){
var store = $('<div/>').addClass('pane').append($('<div/>').addClass('store-checkin').text("COLLECT HERE"));
}

Created lot of divs like this in ajax call, now i want to change the text of selcted div, how can i do it.

tried in this way:
$(“.pane .store-checkin”).on(‘click’, function(){

		$("this").text("SELECTED").addClass('selected');

	}); 

no luck any other work around.

$("this") will look for the <this> element, which is certainly not what you intended.

Ooh, does that mean $(this) instead is likely to lead to success?

By the way $(this) is also not working…anything I am missing here?

try

$(".pane .store-checkin").on('click', function() {
    this.textContent = 'selected';
    this.classList.add('selected');
}

it will give you an error message, if it fails for some reason.

@Dormilich: No luck, I am keeping the code in ajax call itself and wjile keeping your code it’s not throwing any error and as well as popup is also not working.(I am creating a div in the popup window)

then your code is flawed somewhere else.

@Dormilich: The whole content which I am building is in popup and with jquery, is there any other way to select the elements on them and also can you tell I am assigning the div structure to a variable(in My case is store so can i call with that variable like store.store-checkin like that.

@Dormilich

Tried in the below way it’s working, just wanted to share this in future it will be helpful to someone :slight_smile:

$(document).on('click','.store-checkin', function(){
		$("this").text("SELECTED").addClass('selected');
	});

I doubt that work.

I need one more help please check the div structure below, I have number of div’s like below. If I clicked on collect here adding one class ‘selected’ if I selected another one it should be toggle. How to toggle here.

<div class="pane">
	<h3>Heading comes here</h3>
	<p>test</p>					
	<div class="store-checkin">COLLECT HERE</div>
	</div>

[quote=“koder, post:11, topic:229558, full:true”]
I need one more help please check the div structure below, I have number of div’s like below. If I clicked on collect here adding one class ‘selected’ if I selected another one it should be toggle. How to toggle here.[/quote]

First remove ‘selected’ from all of them, then add it to only the one that was clicked.

The same thing I am doing, but If I selected “collect here” on first div adding “selected” class to it and if i am clicking “collect here” on another 2nd div, need to remove selected class from 1st div and add it to 2nd div, by clicking class is adding but not toggling.

First remove ‘selected’ from all of them, then add it to only the one that was clicked.

(this reply has been deliberately repeated for good reason)

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.