i have such div:

<div id="file.jpg">
	<img src="http://localhost/joomla15/uploads/banners/file.jpg?1300447751">
	<img title="Trinti" class="deleteAd" data-filename="file.jpg" src="http://localhost/joomla15/components/com_banerioikelimas/images/delete.png">
	<a class="pratestiDienai">Pratesti galiojima dienai</a><br><br>
	<p class="validUntil">Galioja iki:2011-04-02 20:40:09</p>
	<p>Paspausta:1</p><br>
</div>

now I want to change its html content with such code:

$('#file1.jpg').html('test');

and it doesn't change. Probably because he thinks that .jpg is a class. How to make him think that it is not a class but just id is file1.jpg?

Recommended Answers

All 5 Replies

Try something like this. I didn't check the implications of height not changing in the individual tags. Here you go.

<div id="file.jpg">
	<div class = 'mark'></div>
	<img src="http://localhost/joomla15/uploads/banners/file.jpg?1300447751">
	<img title="Trinti" class="deleteAd" data-filename="file.jpg" src="http://localhost/joomla15/components/com_banerioikelimas/images/delete.png">
	<a class="pratestiDienai">Pratesti galiojima dienai</a><br><br>
	<p class="validUntil">Galioja iki:2011-04-02 20:40:09</p>
	<p>Paspausta:1</p><br>
</div>
<script type='text/javascript'>
	$(document).ready(function(){
		$('img').html('');
		$('a').html('');
		$('p').html('');
		$('div.mark').html('<b>You can do it</b>');
	});
</script>

jQuery knows about your div. What I'm doing is dealing with all the individual components in the div before I change the text. I added the extra div to give me a target to write to.

yeah, your example would be good but the problem is thant I am getting html conntents through ajax, so I want to put them in one div id="x". There are several such divs.

In your example I have to get the html few times - as much as there is different elements inside the div, which means the same ammount of ajax calls. I tried recently using JSON but that didn;t help sendent html code through it. Also the problem is when I want to change somehting, it becomes more difficult. It is easier to have all html for such div in one place and load it all at once.

Currently after AJAX I refresh all divs e.g. div id = 'file1', div id = 'file2' but I only need to modify information in one of those. So it loads slower when I reload all of them. But maybe I will have to just change the id to simply a number, those filenames are in database as well, they also have id's so I could use those numbers instead of filenames for recognition. I will have to modify php functions which work with them, but probably that is easiest way. Probably I should always make id's using simple numbers to avoid such situations. Or at least not use dots in them :D

No problem. I worked with what you posted. Post more and I will try and help more.

thanks, I will definitelly do that when something will become unclear :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.