# Conditional Ajax request

**URL:** <https://www.ruby-forum.com/t/conditional-ajax-request/127897>\
**Category:** Rails\
**Created:** [February 2, 2008, 10:07am UTC](https://www.ruby-forum.com/t/conditional-ajax-request/127897 "2008-02-02T10:07:49Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![veeraa2003](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/b487fb/32.png) [@veeraa2003](https://www.ruby-forum.com/u/veeraa2003)\
**Post date:** [February 2, 2008, 10:07am UTC](https://www.ruby-forum.com/t/conditional-ajax-request/127897/1 "2008-02-02T10:07:49Z")

</div>

Hi Everybody!

I have an ajax request, it will replace a div content with partial file  
like below.

render :update do |page|  
page.replace\_html :track\_info, :partial =\>“shared/trackinfo”  
end

Here i want to check whether the div exists or not, before replacing its  
content. Like below

if $(‘track\_info’)  
$(‘track\_info’).innerHTML=“playlist info partial content”  
else  
#do nothing.

Can anyone suggest me conditional ajax statement for the above  
condition.

Thanks in advance.  
T.Veeraa

---

<div class="post-metadata">

**Author:** ![veeraa2003](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/b487fb/32.png) [@veeraa2003](https://www.ruby-forum.com/u/veeraa2003)\
**Post date:** [February 2, 2008, 11:45pm UTC](https://www.ruby-forum.com/t/conditional-ajax-request/127897/2 "2008-02-02T23:45:25Z")

</div>

Maybe you can try the below one:

page.select(“#track\_info”).each do |value|  
page.replace\_html “track\_info”, :partial =\> “shared/trackinfo”  
end

On Feb 2, 2008 5:07 PM, Veera S.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![veeraa2003](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/b487fb/32.png) [@veeraa2003](https://www.ruby-forum.com/u/veeraa2003)\
**Post date:** [February 4, 2008, 5:16am UTC](https://www.ruby-forum.com/t/conditional-ajax-request/127897/3 "2008-02-04T05:16:02Z")

</div>

sishen wrote:

> Maybe you can try the below one:
> 
> page.select(“#track\_info”).each do |value|  
> page.replace\_html “track\_info”, :partial =\> “shared/trackinfo”  
> end
> 
> On Feb 2, 2008 5:07 PM, Veera S.  
> [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

Hi sishen,

Its working thanks for your kind reply.

Regards,  
T.Veeraa.
